문제

ASP.NET 애플리케이션의 LOB (Logging Application Block)와 예외 처리 응용 프로그램 블록과 함께 처리되지 않은 예외를 기록하고 있습니다. Global.asax의 application_error 메소드를 사용하여 이러한 오류를 포착합니다. 롤링 플랫 파일에 글을 쓰고 있습니다. 이 모든 것이 잘 작동합니다.

또한 Web.Config의 AppSettings 섹션에서 스위치를 설정할 때 실험실을 사용하여 디버그 메시지를 로그고 싶습니다. 하지만이 디버그 메시지를 다른 로그 파일. 누군가가 내 코드와 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>
도움이 되었습니까?

해결책

나는 그것을 제거하는 것을 발견했다 using (new Tracer("Debugging")) 그리고 추가 log.Categories.Add("Debugging"); 상기 방법으로는 원하는 결과를 생성했습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top