I'm adding tracing functionality to an ASP.NET website so I decided to investigate TraceSource by creating a couple of prototypes; a Web Application project and a Website project.
I'm using similar Web.config for each project to log traces to the Windows Event Log:
<configuration>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0"/>
</system.web>
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="HelloWorld">
<listeners>
<add name="eventlogListener" />
</listeners>
</source>
</sources>
<sharedListeners>
<add name="eventlogListener" type="System.Diagnostics.EventLogTraceListener" initializeData="My Source" />
</sharedListeners>
</system.diagnostics>
</configuration>
I'm simply starting with the following basic trace:
private static TraceSource _ts = new TraceSource("HelloWorld", SourceLevels.All);
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
_ts.TraceEvent(TraceEventType.Information, 10, "Greetings from OnLoad.");
}
With the Web Application project, I can see the trace created in the Event Log. However, with the Website project, I cannot.
Are additional steps (Ex: web.config settings, permissions, etc) required with the Website projects to use TraceSource?