【问题标题】:Enterprise Library 5 logging: Why this simple TextFormatter surrounds log entries with dashed?Enterprise Library 5 日志记录:为什么这个简单的 TextFormatter 用虚线包围日志条目?
【发布时间】:2015-09-03 05:25:16
【问题描述】:

使用 Enterprise Library 5 日志记录。我有一个简单的文本 TextFormatter 应该生成如下 CSV 文件:

<formatters>
  <add template="{timestamp(MM/dd/yyyy HH:mm:ss.fff)},{message}" 
        type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
        name="CommaSeparated" />
</formatters>

问题是文本文件中的日志条目总是被如下破折号包围:

----------------------------------------
09/02/2015 20:12:01.591,message 1
----------------------------------------
----------------------------------------
09/02/2015 20:12:01.591,message 2
----------------------------------------
----------------------------------------
09/02/2015 20:12:01.591,message 3
----------------------------------------
----------------------------------------
09/02/2015 20:17:02.028,message 4
----------------------------------------
----------------------------------------
09/02/2015 20:17:02.028,message 5
----------------------------------------
----------------------------------------
09/02/2015 20:17:02.028,message 6
----------------------------------------

破折号来自哪里?我该如何消除它们?我只需要一个纯 CSV 格式。

任何帮助将不胜感激。

【问题讨论】:

    标签: logging enterprise-library-5


    【解决方案1】:

    基于文件的跟踪侦听器的默认页眉和页脚值(如果未指定)是----------------------------------------,这就是您在日志文件中看到它们的原因。它实际上与格式化程序无关,而是与 TraceListener 相关。要不使用破折号,只需将页眉和页脚设置为空字符串:

    <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=31bf3856ad364e35"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        fileName="trace.log" header="" footer="" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-02
      • 1970-01-01
      • 1970-01-01
      • 2011-01-29
      • 1970-01-01
      相关资源
      最近更新 更多