2009-06-16 16 views
1

ASP.NETアプリケーションでロギングアプリケーションブロック(LAB)を使用して、例外処理アプリケーションブロックを使用して未処理例外を記録しています。私はこれらのエラーをキャッチするGlobal.asaxでApplication_Errorメソッドを利用しています。私はローリングフラットファイルに書いています。これはすべて正常に動作します。ロギングアプリケーションブロックを使用してデバッグ情報を書き込む

web.configのappSettingsセクションでスイッチを設定すると、LABを使用してデバッグメッセージを記録することもできます。しかし、これらのデバッグメッセージを別のログファイルに送信する方法を理解できません。誰かが自分のコードとweb.configのセクションを見て、何かが飛び出すかどうかを見れば本当に感謝しています。ありがとう!ここで

は、私は現在、デバッグロガーに書き込みをしようとしている方法の例です:ここで

private void LogDebugInfo() 
{ 
    using (new Tracer("Debugging")) 
    { 
     StringBuilder msg = new StringBuilder(); 
     msg.AppendLine("Querystring: " + Request.QueryString.ToString()); 

     foreach (string item in Request.Form) 
     { 
      msg.AppendLine("Form item name: " + item + " value: " + Request.Form[item]); 
     } 

     HttpFileCollection files = Request.Files; 
     foreach (string f in files) 
     { 
      msg.AppendLine("Posted filename: " + files[f].FileName + " type: " + files[f].ContentType + " length: " + files[f].ContentLength); 
     } 

     LogEntry log = new LogEntry(); 
     log.Message = msg.ToString(); 
     Logger.Write(log); 
    } 
} 

は、web.configファイルから関連するセクションです:

<loggingConfiguration name="Logging Application Block" tracingEnabled="true" 
    defaultCategory="Data Access" logWarningsWhenNoCategoriesMatch="true"> 
    <listeners> 
     <add fileName="log\Data Access.log" rollSizeKB="0" timeStampPattern="yyyy-MM-dd" 
      rollFileExistsBehavior="Increment" rollInterval="Day" formatter="Text Formatter" 
      header="----------------------------------------" footer="----------------------------------------" 
      listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
      traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
      name="Data Access TraceListener" /> 
     <add fileName="log\Debugging.log" rollSizeKB="0" timeStampPattern="yyyy-MM-dd" 
      rollFileExistsBehavior="Increment" rollInterval="Day" formatter="Text Formatter" 
      header="----------------------------------------" footer="----------------------------------------" 
      listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
      traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
      name="Debugging TraceListener" /> 
     <add fileName="log\General Exceptions.log" rollSizeKB="0" timeStampPattern="yyyy-MM-dd" 
      rollFileExistsBehavior="Increment" rollInterval="Day" formatter="Text Formatter" 
      header="----------------------------------------" footer="----------------------------------------" 
      listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
      traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
      name="Log TraceListener" /> 
    </listeners> 
    <formatters> 
     <add template="Timestamp: {timestamp}&#xA;Message: {message}&#xA;Category: {category}&#xA;Priority: {priority}&#xA;EventId: {eventid}&#xA;Severity: {severity}&#xA;Title:{title}&#xA;Machine: {machine}&#xA;Application Domain: {appDomain}&#xA;Process Id: {processId}&#xA;Process Name: {processName}&#xA;Win32 Thread Id: {win32ThreadId}&#xA;Thread Name: {threadName}&#xA;Extended Properties: {dictionary({key} - {value}&#xA;)}" 
      type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
      name="Text Formatter" /> 
    </formatters> 
    <categorySources> 
     <add switchValue="All" name="Data Access"> 
      <listeners> 
       <add name="Log TraceListener" /> 
      </listeners> 
     </add> 
     <add switchValue="All" name="Debugging"> 
      <listeners> 
       <add name="Debugging TraceListener" /> 
      </listeners> 
     </add> 
     <add switchValue="All" name="General"> 
      <listeners> 
       <add name="Log TraceListener" /> 
      </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="Log TraceListener" /> 
      </listeners> 
     </errors> 
    </specialSources> 
</loggingConfiguration> 

答えて

2

私がいることを発見しましたusing (new Tracer("Debugging"))を除去し、log.Categories.Add("Debugging");を上記の方法に加えることにより、所望の結果が得られた。