TraceSource and ASP.NET: works for web applications, not websites

I am adding a trace function to the ASP.NET website, so I decided to investigate TraceSource by creating a couple of prototypes; web application design and website design.

I use a similar Web.config for each project to register traces in 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 just start 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.");
}

In the Web Application project, I see the trace created in the event log. However, with a website project I cannot.

Are there additional steps (for example: web.config settings, permissions, etc.) needed to use website projects to use TraceSource?

+3
source share
2 answers

, , system.codedom\compilers node web.config, , .

0

, Trace .Net, TRACE . - - web.config, :

  <system.codedom>
    <compilers>
      <compiler
         language="c#;cs;csharp"
         extension=".cs"
         type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.50727.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
         compilerOptions="/d:TRACE"
         warningLevel="1" />
    </compilers>
  </system.codedom>

"/d: TRACE", TRACE (# ).

+7

All Articles