2009-07-24 6 views
60

사용자 정의 추적 수신기 (TextWriteTraceListener에서 파생 됨)를 구현했으며 지금은 표준 TextWriteTraceListener 대신 응용 프로그램을 사용하도록 설정하려고합니다.app.config에서 사용자 정의 TraceListener를 정의하는 방법

처음에는 제대로 작동하는지 확인하기 위해 기본값 인 TextWriteTraceListener을 추가했습니다. 여기 제의 app.config의 :

<configuration> 
    <system.diagnostics> 
     <trace autoflush="true" indentsize="4"> 
      <listeners> 
       <add name="TextListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="trace.log" /> 
      <remove name="Default" /> 
      </listeners> 
     </trace> 
    </system.diagnostics> 
</configuration> 

이제 내 추적 수신기가 MyApp.Utils 네임 스페이스에 정의되어 있으며 FormattedTextWriterTraceListener를 불렀다. 그래서 MyApp.Utils.FormattedTextWriterTraceListener에 위의 설정에서 유형을 변경하고 현재처럼 보이는 :

<configuration> 
    <system.diagnostics> 
     <trace autoflush="true" indentsize="4"> 
      <listeners> 
       <add name="MyTextListener" type="MyApp.Utils.FormattedTextWriterTraceListener" initializeData="trace.log" /> 
      <remove name="Default" /> 
      </listeners> 
     </trace> 
    </system.diagnostics> 
</configuration> 

을하지만 지금은 내가 메시지와 함께 ConfigurationErrorsException 받고 있어요 뭔가 로그온 할 때 :

Couldn't find type for class MyApp.Utils.FormattedTextWriterTraceListener.

을 누구든지 구성에서이 사용자 지정 수신기를 설정할 수있는 방법을 알고 있으며 가능한 경우에도 가능합니까?

답변

75

과 같이, 너무 어셈블리를 지정하십시오 :

<configuration> 
    <system.diagnostics> 
     <trace autoflush="true" indentsize="4"> 
      <listeners> 
       <add name="TextListener" 
        type="MyApp.Utils.FormattedTextWriterTraceListener, MyApp" 
        initializeData="trace.log" /> 
      <remove name="Default" /> 
      </listeners> 
     </trace> 
    </system.diagnostics> 
</configuration> 
+0

어셈블리 이름은'MyApp' 내가 형식 인수 – RaYell

+1

에 내가 게시물을 편집 한 것으로, 그 –

+1

이 다른 메시지를주고있다처럼 지정하려고 추가 예외 유형)'MyApp.Utils.FormattedTextWriterTraceListener, MyApp를 만들 수 없습니다. – RaYell

3

을 내가 최근에 그냥 케이스에 사람을 도움이 고민 봤는데 ...

을 내 타입이 그래서 내가 쓴 존재 알고 있었다 다음 : 내 경우

Assembly assembly = System.Reflection.Assembly.GetAssembly(typeof("yourclassname")); 
Type myClassType = assembly.GetType("yournamespace.yourclassname"); 

을 myClassType.AssemblyQualifiedName 내가 type 속성 내 app.config 파일에 필요한 문자열이 포함되어 있습니다. 예를 들어

는 (같은

enter image description here

<system.diagnostics> 
    <sources> 
     <source name="System.ServiceModel" switchValue="Information,ActivityTracing" propagateActivity="true"> 
     <listeners> 
      <add name="CircularTraceListener" /> 
     </listeners> 
     </source> 
    </sources> 
    <sharedListeners> 
     <add name="CircularTraceListener" type="Microsoft.Samples.ServiceModel.CircularTraceListener, CircularTraceListener, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" 
      initializeData="C:\MyWebService\APILog\CircularTracing-service.svclog" maxFileSizeKB="1000" /> 
    </sharedListeners> 
    <trace autoflush="true" /> 
    </system.diagnostics> 
관련 문제