热配置EnterpriseLibrary.Logging仅输出消息和时间戳

时间:2010-04-07 14:54:00

标签: enterprise-library

我正在尝试将简单字符串记录到日志文件中。 我只需要分类,消息和时间戳。 因此我已经像这样配置了app.config:

<listeners>
  <add name="Flat File Destination"
       fileName="C:\Log\Phoenix.Common.Tests\Debug.log"
       header="-----------------------------------------------------------------"
       formatter="Text Formatter" footer="" rollFileExistsBehavior="Increment" rollInterval="Midnight" rollSizeKB="0" timeStampPattern="yyyy-MM-dd" 
       listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
       type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</listeners>
<formatters>
  <add name="Text Formatter" template="Category: {category} Message: {message} Timestamp: {timestamp}"
    type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</formatters>

但我在日志文件中得到了所有其他内容:

Priority: 50 
EventId: 50 Severity: Verbose
Title:Testing Log
Machine: DK-PC-P4740
App Domain: TestAppDomain: 80803a4f-8e18-47bb-901e-cdac784c8041
ProcessId: 6492
Process Name: C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\QTAgent32.exe

如何避免这些额外的东西? 有人可以发送一个链接到一个只将消息记录到日志文件中的示例吗?

1 个答案:

答案 0 :(得分:0)

你现在可能已经弄明白了......

只需将app.config部分中的模板更改为

template="{timestamp(local)}: {message}"

您可能想删除标题&amp;该部分中的页脚字符串也是如此。例如头= “”