使用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格式。
任何帮助都将不胜感激。
答案 0 :(得分:-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="" />