Question

The following listener will create an event entry when the Trace.WriteLine is called. If the source does not exist he will create it in the default log channel which is 'Application' . I want to specify another default Log channel but after searching for 45 minutes i don't seem to find the solution. Any ideas?

<configuration>   
  <system.diagnostics>
    <trace autoflush="false" indentsize="4">
      <listeners>
        <add name="myListener"               
          type="System.Diagnostics.EventLogTraceListener"
          initializeData="Source">          
        </add>
      </listeners>
    </trace>
  </system.diagnostics>
</configuration>
Was it helpful?

Solution

Not sure that you can via the config.

Though the EventLogTraceListener does accept a different eventlog as a parameter in the constructor. Unfortunately, the class is sealed so you can't simply derive from it and pass a different value for the constructor.

Though you could follow this approach and construct your own class(seems fairly simple). And then reference that type in your config. http://weblogs.asp.net/psteele/archive/2006/02/23/438936.aspx

OTHER TIPS

You could repoint the listener in the first line of code.

Trace.Listeners["MyListener"].Attributes["EventLog"] = ConfigurationManager.AppSettings["MyCustomEventLogName"];

The value can be stored in the <appSettings> section of the config file so it's still configuration based:

<appSettings>
    <add key="MyCustomEventLogName" value="CustomEventLogName" />
</appSettings>

You can find a solution for this in this blog post:

http://weblogs.asp.net/psteele/438936

It really works!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top