Enterprise Library 5.0,记录文本日志。记录至某一Category时,defaultCategory也被同时记录内容了,如何不被同时记录?
--------------------编程问答-------------------- 代码:LogEntry logEntry = new LogEntry();
logEntry.Message = "abcde";
logEntry.Severity = System.Diagnostics.TraceEventType.Warning;
logEntry.Categories.Clear();
logEntry.Categories.Add("Db category");
int x = logEntry.Categories.Count; //x=1
Logger.Write(logEntry);//同时记了Main category与Db category
--------------------编程问答-------------------- 沉的叫一个深,帮帮我 --------------------编程问答-------------------- 参考 --------------------编程问答-------------------- 顶......... --------------------编程问答-------------------- 贴配置文件:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<loggingConfiguration name="" tracingEnabled="true" defaultCategory="Main category"
logWarningsWhenNoCategoriesMatch="true">
<listeners>
<add name="Main Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="Log\\main.log" footer="" formatter="Text Formatter 4 Main"
header="" rollInterval="Midnight" timeStampPattern="yyyy-MM-dd" />
<add name="Db Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="Log\\db.log" footer="" formatter="Text Formatter 4 Db"
header="" rollInterval="Midnight" />
</listeners>
<formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
template="{timestamp(local:HH:mm:ss)}|{severity}|{message}"
name="Text Formatter 4 Main" />
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
template="{timestamp(local:HH:mm:ss)}|{severity}|{message}"
name="Text Formatter 4 Db" />
</formatters>
<categorySources>
<add switchValue="All" autoFlush="true" name="Main category">
<listeners>
<add name="Main Listener" />
</listeners>
</add>
<add switchValue="All" name="Db category">
<listeners>
<add name="Db Listener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" autoFlush="true" name="All Events">
<listeners>
<add name="Main Listener" />
</listeners>
</allEvents>
<notProcessed switchValue="All" name="Unprocessed Category">
<listeners>
<add name="Main Listener" />
</listeners>
</notProcessed>
<errors switchValue="All" name="Logging Errors & Warnings">
<listeners>
<add name="Main Listener" />
</listeners>
</errors>
</specialSources>
</loggingConfiguration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
<system.web>
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
</providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
<providers>
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
</providers>
</roleManager>
</system.web>
</configuration>
--------------------编程问答--------------------
看你配置,只有一个categorySources,name是"General"
我配了两个,一个是Main category,默认的;另一个Db category
现在记录至Db category时,Main category被同时记录了,why? --------------------编程问答-------------------- 顶起.. --------------------编程问答-------------------- logEntry.Categories.Clear();
是否在你Clear之前就已经被记录了? --------------------编程问答--------------------
Logger.Write(logEntry)才记录的.
补充:.NET技术 , .NET Framework