Tag: 跟踪监听器

如何在app.config中定义自定义TraceListener

我已经实现了一个自定义的跟踪监听器(派生自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> 现在我的跟踪侦听器是在MyApp.Utils命名空间中定义的,它被称为FormattedTextWriterTraceListener 。 所以我改变了上面的configurationtypes到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> 但是,现在当我尝试logging一些东西,我得到一个ConfigurationErrorsException消息: 无法find类MyApp.Utils.FormattedTextWriterTraceListener的types。 有谁知道我怎么可以在configuration中设置这个自定义侦听器,如果它甚至有可能?