I have a Asp.Net
(Web Api) project. In this project I reference another Class Library project.
The traces that are written in the referenced Class Library don't show up in my Log.
How can I make the traces off both projects show up in the same Log using System.Diagnostics
? In other words, how can I make the referenced Class Library use the web.config
Diagnostics settings from the Api Project? And if this isn't possible, how can I get the Traces that are written in the referenced Class Library in a Log at all?
I tried to add the System.Diagnostics
settings from the web.config
to a app.config
but this doesn't seem to do anything at all.
Api project:
TraceSource source = new TraceSource("MyProject");
source.TraceEvent(TraceEventType.Information, 1, "My logged Trace");
Referenced class library:
TraceSource source = new TraceSource("MyProject");
source.TraceEvent(TraceEventType.Information, 1, "My disappearing Trace");
Web.config
<system.diagnostics>
<sources>
<source name="MyProject" switchValue="All">
<listeners>
<clear />
<add name="log" />
</listeners>
</source>
</sources>
<sharedListeners>
<add name="log"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="Log.svclog"
/>
</sharedListeners>
<trace autoflush="true"/>
</system.diagnostics>
You need to configure trace listeners according to your class library configuration of tracesources. Do you own the code ?
http://msdn.microsoft.com/en-us/library/4y5y10s7.aspx
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.