1
我想通过在app.config文件中添加一个格式器来定制企业库日志记录。问题在于日志API转储附加信息以及我在格式化程序中指定的项目。防止企业库日志记录将日志值添加到日志中
这里是App.config文件
<?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>
我预计它只有一行追加到日志文件:
消息:样品日志文本
但增加以下内容:
消息:“Info”类别没有明确的映射。该 日志条目是:时间戳:31/10/2013上午08点59分01秒
消息:样品日志文本
类别:信息
优先级:2
事件ID:1
严重性:信息
标题:
机:SERVER1
应用程序域:SAMPLE.EXE
的ProcessID:1104
进程名称:
主题名称:
的Win32的ThreadId:9644
扩展属性:
如何摆脱额外的线条?
使用的API是:
Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(message, category, priority)