gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 05:37:20 24 4
gpt4 key购买 nike

我已经实现了一个自定义跟踪监听器(源自 TextWriteTraceListener),现在我想将我的应用程序设置为使用它而不是标准 TextWriteTraceListener

首先,我添加了默认的 TextWriteTraceListener 以确保它可以正常工作。这是我的应用程序配置:

<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.

有谁知道如何在配置中设置此自定义监听器以及是否可能?

最佳答案

也尝试指定一个程序集,如下所示:

<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>

关于.net - 如何在 app.config 中定义自定义 TraceListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1176582/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com