2012-05-02 4 views
1

Microsoft 추적을 사용하도록 일부 코드를 변환 중입니다. 하나의 프로젝트에 모든 리스너를 정의한 다음 명시 적으로로드하지 않고도 다른 어셈블리의 리스너를 사용하는 것이 좋습니다. 명확히하기 위해모든 새 추적 소스에 대한 추적 수신기 자동로드

, 이것은 내가 지금 뭘하는지입니다 :

<?xml version="1.0" encoding="utf-8" ?> 
    <configuration> 
    <system.diagnostics> 
     <trace autoflush="true"> 
     <listeners> 
      <add name="myListener" type="ConsoleApplication4.LogListener, ConsoleApplication4"/> 
      <remove name="Default" /> 
     </listeners> 
     </trace> 
    </system.diagnostics> 
    </configuration> 

그리고 C# 코드에서

: myListener가 자동으로 새에 추가하는

var b = Trace.Listeners; 
TraceSource tr = new TraceSource("Blah", SourceLevels.All); 
tr.Listeners.Add(b["myListener"]); 
tr.TraceEvent(TraceEventType.Warning, 5, "Hello"); 

내가하고 싶은 것은 추적 소스 나는 내가 지금하고있는 방식대로 그것을 보지 않아도 만들어 낸다. 이것이 가능한가?

답변

1

는 설정에서 청취자와 함께 추적 소스를 정의 :

<system.diagnostics> 
    <sources> 
    <source name="Blah" switchValue="Warning"> 
     <listeners> 
     <add name="myListener" /> 
     </listeners> 
    </source> 
    </sources> 
    <!-- Note these are in sharedListeners rather than trace --> 
    <sharedListeners> 
    <add name="myListener" ... /> 
    </sharedListeners> 
    <!-- Autoflush still works as expected --> 
    <trace autoflush="true" /> 
</system.diagnostics> 

그런 다음 코드에서 TraceSource 당신이 이미 (그 추적 레벨 설정에 switchValue에 의해 무시 될 것이다)하는 방법, 돈을 '구성 t 모든 청취자를 추가하고 정상적으로 로그온하십시오.