Logging 阻止企业库日志记录向日志添加默认值
我试图通过在app.config文件中添加格式化程序来自定义企业库日志记录。问题是日志API会将附加信息与我在格式化程序中指定的项一起转储 这是App.config文件Logging 阻止企业库日志记录向日志添加默认值,logging,enterprise-library-5,Logging,Enterprise Library 5,我试图通过在app.config文件中添加格式化程序来自定义企业库日志记录。问题是日志API会将附加信息与我在格式化程序中指定的项一起转储 这是App.config文件 <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="loggingConfiguration" type="Microsoft.Practices.En
<?xml version="1.0" encoding="utf-8" ?>
<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="LoggingBlock" tracingEnabled="true"
defaultCategory="General">
<listeners>
<add name="RollingFile" 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="DataLog.log" formatter="SimpleFormatter" rollFileExistsBehavior="Increment"
rollInterval="Day" rollSizeKB="10000" />
</listeners>
<formatters>
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
template="Message: {message}{newline}
" name="SimpleFormatter" />
</formatters>
<categorySources>
<add switchValue="All" name="General">
<listeners>
<add name="RollingFile" />
</listeners>
</add>
</categorySources>
<specialSources>
<allEvents switchValue="All" name="All Events" />
<notProcessed switchValue="All" name="Unprocessed Category" />
<errors switchValue="All" name="Logging Errors & Warnings" />
</specialSources>
</loggingConfiguration>
</configuration>
最后,我们发现可以通过如下方式覆盖app.config文件中的格式化程序类型来实现:
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
template="[{timestamp(local)}] {category},{machine},{message}"
name="Text Formatter" />
困难在于找到我想添加到日志中的数据的模板关键字
<add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
template="[{timestamp(local)}] {category},{machine},{message}"
name="Text Formatter" />