程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> ASP.NET >> 關於ASP.NET >> Enterprise Library 2.0 -- Logging Application Block(下)

Enterprise Library 2.0 -- Logging Application Block(下)

編輯:關於ASP.NET

閱讀本文之前,請先閱讀: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="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. 下一頁:
Copyright © 程式師世界 All Rights Reserved