我正在使用企业库 5.0 进行日志记录,但我不确定如何关闭日志记录。目前它已打开并正常工作。
这是我关于日志记录的 web.config 部分,它是使用 EL 5.0 GUI 自动创建的。
<loggingConfiguration name="" tracingEnabled="true" defaultCategory="Logging Only">
<listeners>
<add name="Flat File Trace Listener"
type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=..."
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=..."
fileName="WMSlog.log" formatter="Text Formatter" />
<add enabled="false" name="Formatted EventLog TraceListener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=..."
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=..."
source="Exception Handling" formatter="Text Formatter" />
</listeners>
<formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=..."
template="Timestamp: {timestamp}{newline}
Message: {message}{newline}
Category: {category}{newline}
Machine: {localMachine}{newline}
App Domain: {localAppDomain}{newline}
ProcessId: {localProcessId}{newline}
Process Name: {localProcessName}{newline}
Thread Name: {threadName}{newline}
Win32 ThreadId:{win32ThreadId}{newline}"
name="Text Formatter" />
</formatters>
<categorySources>
<add switchValue="Information" name="Logging Only">
<listeners>
<add name="Flat File Trace Listener" />
</listeners>
</add>
<add switchValue="Error" name="Errors Only">
<listeners>
<add name="Formatted EventLog TraceListener" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="Information" name="Logging Errors & Warnings" />
</specialSources>
</loggingConfiguration>
在上面的某些行中,我已经用 ... 替换了我的数据。
目前我正在使用它来登录文件:
if (Logger.IsLoggingEnabled())
{
Logger.Write("Some text...");
}
我需要能够让 Logger.IsLoggingEnabled() 返回 false,我该怎么做?