问题描述
嗨伙计们!
我目前正面临一个问题,无法弄清楚出了什么问题。
在我的应用程序中,我使用了一个简单的插件架构。为了调试,我想在跟踪中写入文本。我在Plugin.dll中设置了一个TraceSource:
Hi Folks!
I''m currently facing a problem and cannot figure out what''s wrong.
In my application, I use a simple Plugin architecture. For debugging, I want to write text to my trace. I have set up a TraceSource within the Plugin.dll:
private static readonly TraceSource ts = new TraceSource("Plugin");
应用程序app.config包含:
The application app.config contains:
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="defaultLogListener"/>
</listeners>
</trace>
<sources>
<source name="Plugin" switchValue="All">
<listeners>
<remove name="Default"/>
<add name="defaultLogListener"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add name="defaultLogListener"
type="System.Diagnostics.ConsoleTraceListener"
traceOutputOptions="Timestamp"/>
</sharedListeners>
</system.diagnostics>
从应用程序内部进行跟踪工作,但我没有从plugin.dll中获取消息由
Tracing from within the application works, but I don''t get the messages from within the plugin.dll raised by
ts.TraceInformation("TRACE from Plugin");
我做错了什么?我是否必须将TraceSource从我的应用程序传递到插件而不是在里面创建一个新的?
非常感谢提前
罗文
What am I doing wrong? Do I have to pass a TraceSource from my application to the Plugin instead of creating a new one inside?
Thanks a lot in advance
Rowan
推荐答案
<system.diagnostics>
<trace autoflush="true" indentsize="4">
<listeners>
<add name="defaultLogListener" />
<add name="defaultFileListener" />
</listeners>
</trace>
<sources>
<source name="ImporterPlugin" switchvalue="All">
<listeners>
<add name="defaultLogListener" />
<add name="defaultFileListener" />
</listeners>
</source>
</sources>
<sharedlisteners>
<add name="defaultLogListener">
type="System.Diagnostics.ConsoleTraceListener"
traceOutputOptions="Timestamp"/>
<add name="defaultFileListener">
type="System.Diagnostics.TextWriterTraceListener"
initializeData="application.log" />
</add></add></sharedlisteners>
</system.diagnostics>
这篇关于来自不同程序集的C#TraceSource(插件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!