ExceptionHandling Logging to Event Viewer in Win Server 2008

Topics: Exception Handling Application Block, Logging Application Block
Dec 30, 2009 at 9:37 AM
Edited Dec 31, 2009 at 2:56 AM

Hi,

I am using Windows Server 2008 for my application (with Ms Ent Lib 4.0), when i debug in my local (using win XP), it will log the error.

However in win server 2008, I could not find my error, even I have thrown the error purposely.

Does anyone know what could be the problem and how to solve this?

My code is to log to event viewer is

ExceptionPolicy.HandleException(ex, "Logging Policy")

My web.config is

<configSections>
        <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </configSections>
    <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
      defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
        <listeners>
            <add source="Auto-Interest" formatter="Text Formatter" log="Application"
              machineName="." listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
              traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
              name="Event Log Destination" />
        </listeners>
        <formatters>
            <add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
              type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
              name="Text Formatter" />
        </formatters>
        <categorySources>
            <add switchValue="All" name="General">
                <listeners>
                    <add name="Event Log Destination" />
                </listeners>
            </add>
        </categorySources>
        <specialSources>
            <allEvents switchValue="All" name="All Events" />
            <notProcessed switchValue="All" name="Unprocessed Category" />
            <errors switchValue="All" name="Logging Errors &amp; Warnings">
                <listeners>
                    <add name="Event Log Destination" />
                </listeners>
            </errors>
        </specialSources>
    </loggingConfiguration>
    <exceptionHandling>
        <exceptionPolicies>
            <add name="Logging Policy">
                <exceptionTypes>
                    <add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                      postHandlingAction="NotifyRethrow" name="Exception">
                        <exceptionHandlers>
                            <add logCategory="General" eventId="100" severity="Error" title="Auto-Interest Exception Handling"
                              formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                              priority="0" useDefaultLogger="true" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                              name="Logging Handler" />
                        </exceptionHandlers>
                    </add>
                </exceptionTypes>
            </add>
        </exceptionPolicies>
    </exceptionHandling>

Thanks.

Dec 31, 2009 at 10:19 PM

I have the same problem http://entlib.codeplex.com/Thread/View.aspx?ThreadId=79301. Does any one have any suggestions?

Thanks,

Asif

Jan 2, 2010 at 1:09 PM

I have the same problem with Windows 7 or Server 2008 R2, I have tried Normal user rights or administrator rights but nothing happend.

I have encountered that the problem is only if I change one part of the configuration

<loggingConfiguration name="Logging Application Block" tracingEnabled="true"
    defaultCategory="Category" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <add source="Enterprise Library Logging" formatter="Text" log="Application"
        machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        traceOutputOptions="Callstack" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="EventLog" />
    </listeners>

Now If I change the source property of the Listener "EventLog" to for example "Test", the ExceptionHandling didn't log any exception, only when I leave it at the default value: "Enterprise Library Logging"

Can any one confirm that behavier?

Best regards

Jan 2, 2010 at 6:15 PM

Hi:

Strange, changing the name of the" Eventlog" listener does not have any affect in my case. Regardless of the name I am not able to log to the event log nor write any thing to trace file. I am using Enterprise Library 4.1. Here is my logging configuration

  <loggingConfiguration name="Logging Application Block" tracingEnabled="true"

    defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">

    <listeners>

      <add fileName="trace.log" header="----------------------------------------"

        footer="----------------------------------------" formatter=""

        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

        traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

        name="FlatFile TraceListener" />

      <add source="Enterprise Library Logging" formatter="Text Formatter"

        log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

        traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

        name="Formatted EventLog TraceListener" />

    </listeners>

    <formatters>

      <add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"

        type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

        name="Text Formatter" />

    </formatters>

    <categorySources>

      <add switchValue="All" name="General">

        <listeners>

          <add name="Formatted EventLog TraceListener" />

          <add name="FlatFile TraceListener" />

        </listeners>

      </add>

    </categorySources>

    <specialSources>

      <allEvents switchValue="All" name="All Events" />

      <notProcessed switchValue="All" name="Unprocessed Category" />

      <errors switchValue="All" name="Logging Errors &amp; Warnings">

        <listeners>

          <add name="Formatted EventLog TraceListener" />

          <add name="FlatFile TraceListener" />

        </listeners>

      </errors>

    </specialSources>

  </loggingConfiguration>

 

-Asif

 

  <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
    defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <add fileName="trace.log" header="----------------------------------------"
        footer="----------------------------------------" formatter=""
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="FlatFile TraceListener" />
      <add source="Enterprise Library Logging" formatter="Text Formatter"
        log="Application" machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Formatted EventLog TraceListener" />
    </listeners>
    <formatters>
      <add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
        type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="General">
        <listeners>
          <add name="Formatted EventLog TraceListener" />
          <add name="FlatFile TraceListener" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events" />
      <notProcessed switchValue="All" name="Unprocessed Category" />
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Formatted EventLog TraceListener" />
          <add name="FlatFile TraceListener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>

 

 

Jan 3, 2010 at 11:41 AM

jp_miata, how do you get it work?

May i know your full config file?

Is this a bug for Microsoft enterprise library 4.0 for Windows Server 2008??

Jan 5, 2010 at 2:31 AM
Edited Jan 5, 2010 at 2:40 AM

It might be a permission issue.  Please check the write permission first on the EventViewer.  Something like this although this is for windows server 2003 - http://support.microsoft.com/kb/323076

Here is also a related FAQ - http://entlib.codeplex.com/wikipage?title=Why%20are%20messages%20not%20logged%3f&referringTitle=EntLib%20FAQ

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com

Jan 6, 2010 at 12:18 PM

I have sloved my problem, since the application has full privilages it works.

  <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
    defaultCategory="Category" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <add source="Test" formatter="Text" log="Application"
        machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        traceOutputOptions="Callstack" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="EventLog" />
    </listeners>
    <formatters>
      <add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
        type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        name="Text" />
    </formatters>
    <categorySources>
      <add switchValue="All" name="Category">
        <listeners>
          <add name="EventLog" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events" />
      <notProcessed switchValue="All" name="Unprocessed Category" />
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="EventLog" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
  <exceptionHandling>
    <exceptionPolicies>
      <add name="General">
        <exceptionTypes>
          <add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="NotifyRethrow" name="Exception">
            <exceptionHandlers>
              <add logCategory="Category" eventId="100" severity="Error" title="Enterprise Library Exception Handling"
                formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                priority="0" useDefaultLogger="false" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                name="Logging Handler" />
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
    </exceptionPolicies>
  </exceptionHandling>

Best regards

Jan 13, 2010 at 9:49 AM

Hi all,

Two temporary solution to this:

1) Change the logging to eventlog to log to flat files

2) Add in the application name to the registry manually.

http://support.microsoft.com/default.aspx?scid=kb;en-us;329291

Weird thing is that my application is using administrator to run and by right administrator is able to create new key on registry.

But after you add the app name to the registry, the error is logged in the event log however there's this kind of header:

The description for Event ID <100> from source <Application> cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.

If the event originated on another computer, the display information had to be saved with the event.

The following information was included with the event:

<The error message>

So if anyone know how to remove the error header, pls let me know.

Thanks.

Jan 19, 2010 at 7:36 AM

What value did you use for the Source property of the event log trace listener?  It's possible that that event source does not exists on your machine, you can check it by using this code:

bool exists = System.Diagnostics.EventLog.SourceExists("LogSource");

and if exists is false, you can create it by:

System.Diagnostics.EventLog.CreateEventSource("LogSource", "Application");

where "Application" corresponds to the Log property of your trace listener.

If you're using the default "Enterprise Library Logging" as the source, you can run InstallServices.bat as this automatically creates that event source as well as the performance counters.

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com