当前位置:主页   - 电脑 - 网站开发 - ASP.Net
Enterprise Library 2.0 -- Logging Application Block (下)
来源:网络   作者:   更新时间:2012-03-26
收藏此页】    【字号    】    【打印】    【关闭

  本文源代码下载地址:

  http://flashview.ddvip.com/2008_11/Enterprise Library2.0.rar 

  阅读本文之前,请先阅读:Enterprise Library 2.0 -- Logging Application Block (上)

  上一篇中我们介绍了如何去配置Logging Application Block,本文将主要介绍Logging Application Block 的基本操作以及Formatter和Trace Listeners 的自定义方法,首先我们来看如何将一个事件日志写入到一个文本文件中。

  假设我们按照上一篇的操作配置了Logging Application Block,那么配置文件中的信息如下:

  <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
  defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
  <listeners>
   <add fileName="trace.log" header="----------------------------------------"
    footer="----------------------------------------" formatter="SHY520 Formatter"
    listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData,
  
Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
    traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener,
  
Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
    name="SHY520 Listeners" />
   <add source="Enterprise Library Logging" formatter="Text Formatter"
    log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData,
  
Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
    traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener,
  
Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
    name="Formatted EventLog TraceListener" />
  </listeners>
  <formatters>
   <add template="Timestamp: {timestamp} Message: {message} Category: {category} Priority: {priority} EventId:
  
{eventid} Severity: {severity} Title:{title} Machine: {machine} Application Domain: {appDomain} Process Id:
  
{processId} Process Name: {processName} Win32 Thread Id: {win32ThreadId} Thread Name: {threadName} Extended Properties:
  
{dictionary({key} - {value} )}"
    type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0,
  
Culture=neutral, PublicKeyToken=null"
    name="Text Formatter" />
   <add template="Timestamp: {timestamp} Message: {message} Category: {category} Priority: {priority} EventId:
  
{eventid} Severity: {severity} Title:{title} Machine: {machine} Application Domain: {appDomain} Process Id:
  
{processId} Process Name: {processName} Win32 Thread Id: {win32ThreadId} Thread Name: {threadName} Extended Properties:
  
{dictionary({key} - {value} )}"
    type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0,
  
Culture=neutral, PublicKeyToken=null"
    name="SHY520 Formatter" />
  </formatters>
  <logFilters>
   <add categoryFilterMode="AllowAllExceptDenied" type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.CategoryFilter,
  
Microsoft.Practices.EnterpriseLibrary.Logging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"
    name=&quot;Category Filter" />
  </logFilters>
  <categorySources>
   <add switchValue="All" name="General">
    <listeners>
     <add name="SHY520 Listeners" />
    </listeners>
   </add>
  </categorySources>
  <specialSources>
   <allEvents switchValue="All" name="All Events" />
   <notProcessed switchValue="All" name="Unprocessed Category" />
   <errors switchValue="All" name="Logging Errors &amp; Warnings">
    <listeners>
     <add name="Formatted EventLog TraceListener" />
    </listeners>
   </errors>
  </specialSources>
 </loggingConfiguration>

其它资源
来源声明

版权与免责声明
1、本站所发布的文章仅供技术交流参考,本站不主张将其做为决策的依据,浏览者可自愿选择采信与否,本站不对因采信这些信息所产生的任何问题负责。
2、本站部分文章来源于网络,其版权为原权利人所有。由于来源之故,有的文章未能获得作者姓名,署“未知”或“佚名”。对于这些文章,有知悉作者姓名的请告知本站,以便及时署名。如果作者要求删除,我们将予以删除。除此之外本站不再承担其它责任。
3、本站部分文章来源于本站原创,本站拥有所有权利。
4、如对本站发布的信息有异议,请联系我们,经本站确认后,将在三个工作日内做出修改或删除处理。
请参阅权责声明