locked
Why is my trace.log file empty? RRS feed

  • Question

  • User-703432812 posted

    I'm using the MS practises enterprise exception logging block and configured everything in the web.config to output exceptions to the trace.log file.

    However when I simulate an exception the trace.log is always empty.  Can anyone give me an insight why this isn't working?  It should be so simple, but there is absolutely no feedback as to what happened, just an empty file!  Quite ironic considering I need this stuff to help me actually debug my application & find out what exceptions are occurring.  However if I can't get this to work at all,  I might have to use an alternative like ELMAH or Log4Net, because this is just plain silly!

    The test page code:

    Imports Microsoft.Practices.EnterpriseLibrary.ExceptionHandling
    
    Partial Class _Default
        Inherits System.Web.UI.Page
    
        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            Try
                Throw New Exception("Hello this is a test")
    
            Catch ex As Exception
                Dim bRethrow As Boolean
    
                bRethrow = ExceptionPolicy.HandleException(ex, "Exception Policy")
    
                If bRethrow Then
                    Throw
                End If
    
            End Try
        End Sub
    End Class

    And here is the web.config which has been created using the Enterprise Library Configuration utility:

    <?xml version="1.0"?>
    <configuration>
      <configSections>
        <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
          <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
            <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />
            <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
              <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere" />
              <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />
              <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />
            </sectionGroup>
          </sectionGroup>
        </sectionGroup>
      </configSections>
      <loggingConfiguration name="Logging Application Block" tracingEnabled="false"
        defaultCategory="" logWarningsWhenNoCategoriesMatch="false">
        <listeners>
          <add fileName="trace.log" header="----------------------------------------"
            footer="----------------------------------------" formatter="Text Formatter"
            listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
            traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
            name="FlatFile TraceListener" />
        </listeners>
        <formatters>
          <add template="Timestamp: {timestamp}
    
    Message: {message}
    
    Category: {category}
    
    Priority: {priority}
    
    EventId: {eventid}
    
    Severity: {severity}
    
    Title:{title}
    
    Machine: {machine}
    
    Application Domain: {appDomain}
    
    Process Id: {processId}
    
    Process Name: {processName}
    
    Win32 Thread Id: {win32ThreadId}
    
    Thread Name: {threadName}
    
    Extended Properties: {dictionary({key} - {value}
    
    )}"
            type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
            name="Text Formatter" />
        </formatters>
        <logFilters>
          <add enabled="true" type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.LogEnabledFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
            name="LogEnabled Filter" />
        </logFilters>
        <categorySources>
          <add switchValue="All" name="Category">
            <listeners>
              <add name="FlatFile TraceListener" />
            </listeners>
          </add>
        </categorySources>
        <specialSources>
          <allEvents switchValue="All" name="All Events">
            <listeners>
              <add name="FlatFile TraceListener" />
            </listeners>
          </allEvents>
          <notProcessed switchValue="All" name="Unprocessed Category">
            <listeners>
              <add name="FlatFile TraceListener" />
            </listeners>
          </notProcessed>
          <errors switchValue="All" name="Logging Errors & Warnings">
            <listeners>
              <add name="FlatFile TraceListener" />
            </listeners>
          </errors>
        </specialSources>
      </loggingConfiguration>
      <exceptionHandling>
        <exceptionPolicies>
          <add name="Exception Policy">
            <exceptionTypes>
              <add type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                postHandlingAction="None" name="Exception" />
            </exceptionTypes>
          </add>
        </exceptionPolicies>
      </exceptionHandling>
      <dataConfiguration>
        <providerMappings>
          <add databaseType="Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
            name="System.Data.SqlClient" />
        </providerMappings>
      </dataConfiguration>
      <appSettings>
        <add key="Setting" value="" />
      </appSettings>
      <system.web>
        <pages>
          <controls>
            <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
          </controls>
        </pages>
        <!--
              Set compilation debug="true" to insert debugging
              symbols into the compiled page. Because this
              affects performance, set this value to true only
              during development.
        -->
        <compilation debug="true">
          <assemblies>
            <add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add assembly="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=3.1.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
            <add assembly="System.Management, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
            <add assembly="System.Configuration.Install, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
            <add assembly="System.Messaging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
          </assemblies>
        </compilation>
        <httpHandlers>
          <remove verb="*" path="*.asmx" />
          <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
          <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
          <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />
        </httpHandlers>
        <httpModules>
          <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        </httpModules>
      </system.web>
      <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <modules>
          <add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        </modules>
        <handlers>
          <remove name="WebServiceHandlerFactory-Integrated" />
          <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
          <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
          <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        </handlers>
      </system.webServer>
    </configuration>



    Tuesday, May 18, 2010 12:20 PM

Answers

  • User-703432812 posted

    Drum roll please....

    1) Because you need to make an explicit call  to the logger.write() method (either in global.asax or within the page class for the error or even inside the catch block).  I thought this was handled intrinsically by ASP.NET.

    2) Another reason was that, I couldn't for whatever reason get trace.log to be written to in the root of the application (permissions problem?).  It will work if I set the path to C:\temp\trace.log.  Even if C:\temp folder doesn't exist the folder still gets created and the log file goes in.

    Hope this helps someone else out....

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 20, 2010 9:52 AM