locked
Unable to log into event log RRS feed

  • Question

  • User-389597101 posted

    Hi

    I have created a web.config file for logging the exceptions in enterprise library. 

     <configSections>
        <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
        <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
      </configSections>
     

      <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
        <listeners>
          <add name="Event Log Listener"
            type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            source="Enterprise Library Logging" formatter="Text Formatter"
            log="Application" machineName="." traceOutputOptions="LogicalOperationsStack" />
        </listeners>
        <formatters>
          <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            template="Timestamp: {timestamp}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Priority: {priority}{newline}&#xA;EventId: {eventid}{newline}&#xA;Severity: {severity}{newline}&#xA;Title:{title}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Thread Name: {threadName}{newline}&#xA;Win32 ThreadId:{win32ThreadId}{newline}&#xA;Extended Properties: {dictionary({key} - {value}{newline})}"
            name="Text Formatter" />
        </formatters>
        <categorySources>
          <add switchValue="All" name="General">
            <listeners>
              <add name="Event Log Listener" />
            </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 Listener" />
            </listeners>
          </errors>
        </specialSources>
      </loggingConfiguration>
      <exceptionHandling>
        <exceptionPolicies>
          <add name="MyPolicy">
            <exceptionTypes>
              <add name="All Exceptions" type="System.Exception, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                postHandlingAction="None" />
            </exceptionTypes>
          </add>
        </exceptionPolicies>
      </exceptionHandling>
      <appSettings>
        <add key="Source" value="Test" />
      </appSettings>

     

    And when ever exception occurs I have written the following code

    Exception ex = new Exception(message);
    Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex, "MyPolicy");

    [\code]

    But I can't see the exception in the event log have I missed something?

    Tuesday, February 21, 2012 4:49 AM

All replies

  • User-837620913 posted

    You are getting errors because your ASP.NET worker process does not have permission to create the new event source "Enterprise Library Logging" in the application event log.

    You need to create the source once and then it will work.  You can either:

    1.  Go in to the registry on the web server using regedit and add the event log source to the application event log.  You can follow the directions here:  http://msdn.microsoft.com/en-us/library/xz73e171(v=VS.90).aspx  or use an app that someone built here:  http://imar.spaanjaars.com/275/logging-errors-to-the-event-log-in-aspnet-applications

    NOTE: You must have admin permissions to create an event source.

    2.  Run the application as an admin using impersonation, and purposely cause an error to be thrown.  Since you have admin permissions, and the web application is impersonating you, then the event source will be created.

    This only needs to be done once per web server and then it will work.  It takes a higher privilege to create an event source, but the ASP.NET worker process identities can write to them fine.

    Tuesday, February 21, 2012 6:29 AM