我已经实现了一个自定义跟踪侦听器(派生自TextWriteTraceListener),现在我想将我的应用程序设置为使用它而不是标准TextWriteTraceListener.
首先,我添加了默认值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>
Run Code Online (Sandbox Code Playgroud)
现在我的跟踪侦听器在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>
Run Code Online (Sandbox Code Playgroud)
但是现在,当我尝试记录一些我正在收到ConfigurationErrorsException消息时:
找不到类MyApp.Utils.FormattedTextWriterTraceListener的类型.
有谁知道如何在配置中设置这个自定义监听器,如果它甚至可能?