Enterprise Library 4.1记录时间戳如何显示毫秒

use*_*979 10 logging enterprise-library app-config

以下是配置文件.

 <formatters>
      <add template="{timestamp} {severity} {category} {message}" type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="SingleLineFormatter" />
 </formatters>
Run Code Online (Sandbox Code Playgroud)

哪个显示

31/05/2011 11:43:24信息......

但是没有毫秒显示哪些对于穿孔仪器有用,谁知道如何显示?谢谢.

Ran*_*ica 19

您可以为时间戳模板标记指定 标准自定义 DateTime格式字符串:

<formatters>
      <add 
        template="{timestamp(MM/dd/yyyy HH:mm:ss.fffffff)} {severity} {category} {message}" 
        type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="SingleLineFormatter" />
 </formatters>
Run Code Online (Sandbox Code Playgroud)

这将输出如下内容:

06/01/2011 20:12:43.3405776信息概述这是消息

默认情况下,DateTime将采用UTC时间.如果您希望使用本地时间,请在格式字符串前加上"local:".例如{timestamp(local:MM/dd/yyyy HH:mm:ss.fffffff)}

此外,如果您要查看方法条目和出口的性能跟踪,您可能需要查看Tracer该类.