Logging Extended Properties Stops Logging of Other Details

Topics: Logging Application Block
Mar 14, 2011 at 2:51 PM

I have been trying to add a unique identifier that I display on my error page to also be shown in the log file, to allow the errors to be tied up by a unique Id (I have used a Guid). Until I added the code to write the extended properties :

     // create a new Guid...
            var exceptionGuid = Guid.NewGuid().ToString();

            // create a new log entry for storing extended properties...
            LogEntry logEntry = new LogEntry { Severity = TraceEventType.Error };

            // store the timestamp for the exception...
            var exceptionTimeStamp = logEntry.TimeStamp;

            // based on the exception type...
            if (exception is ValidationException)
            {
                // set the message text...
                messageText = string.Format(
                    "An error with ID of {0} occurred at {1}",
                    exceptionGuid,
                    exceptionTimeStamp);
            }
            else if (exception is DomainSecurityException)
            {
                // cast the exception to it's correct type...
                var currentException = (DomainSecurityException)exception;

                // set the message text...
                messageText = string.Format(
                    "An error with ID of {0} occurred at {1}",
                    exceptionGuid,
                    exceptionTimeStamp);
            }
            else if (exception is EntityValidationException)
            {
                // cast the exception to it's correct type...
                var currentException = (EntityValidationException)exception;

                // if specific error...
                messageText = string.Format(
                    "An error with ID of {0} occurred at {1}",
                    exceptionGuid,
                    exceptionTimeStamp);
            }
            else if (exception is DomainInternalMessageException)
            {
                // These are the type of errors generated a System.Exception occurs and is
                // converted by the exception handling policy to a more friendly format...

                // cast the exception to it's correct type...
                var currentException = (DomainInternalMessageException)exception;

                // if specific error...
                messageText = string.Format(
                    "An error with ID of {0} occurred at {1}",
                    exceptionGuid,
                    exceptionTimeStamp);
            }
            else if (exception is TimeoutException)
            {
                // if specific error...
                messageText = string.Format(
                    "An error with ID of {0} occurred at {1}",
                    exceptionGuid,
                    exceptionTimeStamp);
            }
            else if (exception is SystemException)
            {
                // if specific error...
                messageText = string.Format(
                    "An error with ID of {0} occurred at {1}",
                    exceptionGuid,
                    exceptionTimeStamp);
            }
            else
            {
                // if specific error...
                messageText = string.Format(
                    "An error with ID of {0} occurred at {1}",
                    exceptionGuid,
                    exceptionTimeStamp);
            }

            // store the Guid into the error data...
            logEntry.ExtendedProperties.Add("ErrorGuid", exceptionGuid);

            // write the data to the logging file...
            Logger.Write(logEntry);

I initially used some code that added the extended properties to the actual exception, which caused the error file to stop being updated, but now I have updated my code to use a LogEntry, it added the extended properties as I wanted, but now the other detail and items in the log are being excluded.

My previous log showed:

Timestamp: 07/03/2011 11:38:14          
Message:
HandlingInstanceID: cebdcc28-218b-480f-b374-f7b8eaa59fe7
An exception of type 'System.NullReferenceException' occurred and was caught.
-----------------------------------------------------------------------------
03/07/2011 11:38:14
Type : System.NullReferenceException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Message : Object reference not set to an instance of an object.
Source : ALT_BLL
Help link :
Data : System.Collections.ListDictionaryInternal
TargetSite : System.Collections.Generic.IList`1[ALT_Shared.Entities.SchemeEntity] GetSchemes(ALT_Shared.Filters.SchemeFilterEntity)
Stack Trace :    at ALT_BLL.Controllers.SchemesController.GetSchemes(SchemeFilterEntity filter) in D:\TFSSandboxes\eSol_Retirements_Asset_Liability_Tracker\Development\AssetLiabilityTracker\ALT_BLL\Controllers\SchemesController.cs:line 276
Additional Info:
MachineName : DESKTOPXXXXX
TimeStamp : 07/03/2011 11:38:14
FullName : Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
AppDomainName : de39e69e-4-129439714732221492
ThreadIdentity : WWP\101119
WindowsIdentity : WWP\101119          
Category: Errors          
Priority: 0          
EventId: 204          
Severity: Error          
Title: System Exception          
Machine: DESKTOPXXXXX          
Application Domain: de39e69e-4-129439714732221492          
Process Id: 5184          
Process Name: C:\Program Files\Common Files\Microsoft Shared\DevServer\9.0\WebDev.WebServer.exe          
Win32 Thread Id: 3208          
Thread Name:          
Extended Properties:
-------------------End Log-------------------

But now shows:

------------------Start Log------------------
Timestamp: 14/03/2011 13:04:20          
Message:          
Category: Errors          
Priority: -1          
EventId: 0          
Severity: Information          
Title:          
Machine: DESKTOPXXXXX          
Application Domain: de39e69e-10-129445814357296033          
Process Id: 2112          
Process Name: C:\Program Files\Common Files\Microsoft Shared\DevServer\9.0\WebDev.WebServer.exe          
Win32 Thread Id: 7732          
Thread Name:          
Extended Properties: ErrorGuid - 6ce015ae-5b30-4de2-95ce-6b9f145cd419
-------------------End Log-------------------

Is this to do with the extended properties? And is there a way to get it back so that it shows the detail in the previous log entry, and the extended properties?
Thanks in advance
Martin

Mar 15, 2011 at 1:56 AM

Looking at each log, I can see they use different format so I think that's what caused the difference and not the addition of the extended properties.  Verify the format of the formatter you're using for the trace listeners.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Mar 15, 2011 at 12:36 PM

I have made no changes to the log format, or any of the logging/trace listener settings between versions, which was why I was confused.

This is my logging configuration block :

<loggingConfiguration name="Logging Application Block" tracingEnabled="true"
    defaultCategory="Errors" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <add name="Error Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        fileName="error.log" header="------------------Start Log------------------"
        footer="-------------------End Log-------------------" formatter="Text Formatter"
        traceOutputOptions="None" filter="All" />
    </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}&#xD;&#xA;&#xD;&#xA;           Message: {message}&#xD;&#xA;&#xD;&#xA;           Category: {category}&#xD;&#xA;&#xD;&#xA;           Priority: {priority}&#xD;&#xA;&#xD;&#xA;           EventId: {eventid}&#xD;&#xA;&#xD;&#xA;           Severity: {severity}&#xD;&#xA;&#xD;&#xA;           Title: {title}&#xD;&#xA;&#xD;&#xA;           Machine: {machine}&#xD;&#xA;&#xD;&#xA;           Application Domain: {appDomain}&#xD;&#xA;&#xD;&#xA;           Process Id: {processId}&#xD;&#xA;&#xD;&#xA;           Process Name: {processName}&#xD;&#xA;&#xD;&#xA;           Win32 Thread Id: {win32ThreadId}&#xD;&#xA;&#xD;&#xA;           Thread Name: {threadName}&#xD;&#xA;&#xD;&#xA;           Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
        name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="Error" name="Errors">
        <listeners>
          <add name="Error Log Listener" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events">
        <listeners>
          <add name="Error Log Listener" />
        </listeners>
      </allEvents>
      <notProcessed switchValue="All" name="Unprocessed Category">
        <listeners>
          <add name="Error Log Listener" />
        </listeners>
      </notProcessed>
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Error Log Listener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>

And this is the exception handling log assigned to each error in the policy:

<add name="Log Internal Message Exception" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, 
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

logCategory="Errors" eventId="201" severity="Error" title="Internal Message Exception"
formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
priority="0" useDefaultLogger="true" />
The only change I made between versions was add the code in my initial post that created and wrote the log entry.
Martin
Mar 16, 2011 at 7:34 AM
Edited Mar 16, 2011 at 8:22 AM

Hi,

Are you also using Entry Log on your original code or are you using the EHAB to take care of logging? I just noticed you had Logging Exception Handler in your config. I think the Logging Exception Handler has its own log message formatter, as you would see in the config:

Hope this helps.

Mar 16, 2011 at 10:05 AM

Hi

Sorry, but not sure I understand your question, or how to answer it - this is all still new and most of what I have done is inherited from another application, so am trying to get to grips with it very late in the development cycle.

As stated, the logging configuration has been set as above, and has not changed. For each exception being handled, I am logging it to the error.log file by using the logging block above, modified for the error type, i.e.

<exceptionHandlers>
<add name="Log System Exception" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
 logCategory="Errors" eventId="204" severity="Error" title="System Exception" 
formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" priority="0" useDefaultLogger="true" />
</exceptionHandlers>

The only change I made between log 1 and log 2 was to add the extended properties code, as shown in my original post, i.e.

            // create a new Guid...
            var exceptionGuid = Guid.NewGuid().ToString();

            // create a new log entry for storing extended properties...
            LogEntry logEntry = new LogEntry();

            // store the timestamp for the exception...
            var exceptionTimeStamp = logEntry.TimeStamp;
...
            // store the Guid into the error data...
            logEntry.ExtendedProperties.Add("ErrorGuid", exceptionGuid);

            // write the data to the logging file...
            Logger.Write(logEntry);

Thanks

Martin

Mar 16, 2011 at 12:23 PM

Hi,

You mentioned on your earlier posts: "I initially used some code that added the extended properties to the actual exception, which caused the error file to stop being updated but now I have updated my code to use a LogEntry... ". So I assume you are using EHAB there in logging the exception. Can you post here that piece of code? If you are familiar with Exception Handling Block, it has a feature there that you can log the exceptions thrown. (You can refer here on how EHAB logs exception.)

This is how it looks like:

 The log format of this is similar to the log you had before you modified your code. I believe you cannot modify its format unlike using Log Entry. Also note that the <exceptionHandler> on your configuration will be irrelevant since you are using the Logging Application Block.

Mar 16, 2011 at 1:00 PM

Hi

Thanks for your reply.

The issue that broke it was the following code, and what it did was stop the error log file being updated when an exception occurred.

// store the timestamp into the error...
actualException.Data.Add("timestamp", DateTime.Now);

After some searching on google, I came up with the solution of using the extended properties, and the idea is to simply pass through a guid that I can use as a reference betwen the error page text and the in-depth log file.

And yes, my exception handling settings are the same as the one you show above - I have two policies, a businesslogiclayerpolicy and a dataaccesslayerpolicy. Each exception I handle via these policies has a log handler, and, as stated, before I added the extended properties, I received the in-depth error logs for each error that occurred in the system.

Thanks

Martin

Mar 16, 2011 at 2:54 PM
daaberkads wrote:

Hi,

Are you also using Entry Log on your original code or are you using the EHAB to take care of logging? I just noticed you had Logging Exception Handler in your config. I think the Logging Exception Handler has its own log message formatter, as you would see in the config:

Hope this helps.


Hi

Can you tell me how to implement the built in log formatter? If I attempt to change the existing item, it shows me a dialog with the option to Add from GAC or Add from file, and the dialog shows:

- Loaded Assemblies
  + Microsoft.Practices.EnterpriseLibrary.ExceptionHandling

And if I implement your suggestion, do I need to remove the formatter section from my EHAB?

Thanks again

Martin

Mar 17, 2011 at 3:08 AM

That is already the built in log formatter, the TextExceptionFormatter.  I think the confusion here is why are you posting the configuration for the LoggingExceptionHandler when it is not really relevant with the call to Logger.Write. 

The LoggingExceptionHandler would only be used when you used the exception policy to which it is attached to in your code (call to ExceptionPolicy.HandleException method).

It would seem to me that the 2 different logs you posted are results of 2 different logging alls, one is through the Logger.Write and the other one is through the call to the HandleException method.

If this still confuses you, kindly send me a small repro for this.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Mar 17, 2011 at 10:37 AM

I understand this less now than when I started LOL

OK. The initial idea was to be able to show an identifier within our sanitised message, and also to ensure that all errors were logged to the log file. I added in the LogEntry code to allow me to share a guid, created when the exception was handled, with the log file.

To log each item, I initially added the LoggingExceptionHandler to each exception within my policies, and this gave me the initial log file. As there was no way to gain access to a unique identifier, I decided to create my guid and pass that across. That's when my problems started.

I think I'll go back to how it was and use the timestamp as the identifier, which will put back all the data that I 'lost'.

Thanks anyway

Martin

 

Mar 17, 2011 at 10:55 AM

I'm sorry if this confuses you.  The behavior you're getting is not something I can repro and your implementation is also something not clear to me.  Based on the 2 versions of log you posted, my guess is that the first one, which contains more detail, is a result of calling the HandleException method:

try
{
}
catch(Exception ex)
{
        bool rethrow = ExceptionPolicy.HandleException(ex, "General Policy");
}

where General Policy is the name of the exception policy defined in your config using the LoggingExceptionHandler whose configuration you posted as:

<exceptionHandlers>
<add name="Log System Exception" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
 logCategory="Errors" eventId="204" severity="Error" title="System Exception" 
formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" priority="0" useDefaultLogger="true" />
</exceptionHandlers>

On the other hand, still as it seems to me, the second one containinig lesser details is a result of calling Logger.Write method:

           // create a new Guid...
            var exceptionGuid = Guid.NewGuid().ToString();

            // create a new log entry for storing extended properties...
            LogEntry logEntry = new LogEntry();

            // store the timestamp for the exception...
            var exceptionTimeStamp = logEntry.TimeStamp;

            // store the Guid into the error data...
            logEntry.ExtendedProperties.Add("ErrorGuid", exceptionGuid);

            // write the data to the logging file...
            Logger.Write(logEntry);

I tried running this code, commenting and uncommenting the line which adds an item in the ExtendedProperties but I didn't get the difference in the logs you're mentioning.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Mar 17, 2011 at 3:21 PM

Hi Sarah

No problem, that's the problem with inheriting code and having no time to implement it yourself.

Anyway, the way we have set this up is as follows:

We have a class (called PageBase) that each code-behind for our web application pages inherit from. Within this we have a method called HandleExp, with a single argument of type Exception.

Each page method/control event is wrapped in a try/catch block, and the catch just calls this.HandleExp and passes over the exception caught.

        public void HandleExp(Exception exception)
        {
            // if exceptiopn not found...
            if (exception == null)
            {
                // simply redirected to a new page...
                return;
            }

            // define which type of exception occurred and deal with accordingly...
            if (exception is System.Threading.ThreadAbortException)
            {
                return;
            }

            // define the date/time for the exception...
            var exceptionTimeStamp = DateTime.Now;

            // define variable to store the exception message...
            string messageText;

            // based on the exception type...
            if (exception is ValidationException)
            {
                // set the message text...
                messageText = string.Format("A validation error occurred at {0}", exceptionTimeStamp);

                // append a new line...
                messageText += Environment.NewLine;

                // append the actual message...
                messageText += exception.Message;
            }
            else if (exception is DomainSecurityException)
            {
                // set the message text...
                messageText = string.Format("A security error occurred at {0}", exceptionTimeStamp);
            }
            else if (exception is EntityValidationException)
            {
                // display the message as a pop-up...
                this.DisplayJavascriptMessage(exception.Message);

                // exit with no further processing...
                return;
            }
            else if (exception is DomainInternalMessageException)
            {
                // cast the exception to it's correct type...
                var currentException = (DomainInternalMessageException)exception;

                // if only a warning...
                if (currentException.MessageSeverity == InternalMessageSeverityType.Warning)
                {
                    // dispaly as a pop-up message...
                    this.DisplayJavascriptMessage(currentException.Message);

                    // exit with no further processing...
                    return;
                }

                // if specific error...
                messageText = string.Format("An internal error occurred at {0}", exceptionTimeStamp);

                // append a new line...
                messageText += Environment.NewLine;

                // append the actual message...
                messageText += currentException.DisplayMessage;
            }
            else if (exception is TimeoutException)
            {
                // if specific error...
                messageText = string.Format("An application timeout occurred at {0}", exceptionTimeStamp);
            }
            else if (exception is SystemException)
            {
                // if specific error...
                messageText = string.Format("A system error occurred at {0}", exceptionTimeStamp);
            }
            else if (exception.InnerException is OptimisticConcurrencyException)
            {
                // set the message text to be displayed...
                messageText = string.Format("A concurrency issue occurred at {0}", exceptionTimeStamp);
            }
            else
            {
                // if specific error...
                messageText = string.Format("An unspecified error occurred at {0}", exceptionTimeStamp);
            }

            // display the message...
            this.DisplayErrorPage(messageText);
        }

The DsplayErrorPage method is there to redirect/transfer control to a specific error page:

        protected void DisplayErrorPage(string errorMessage)
        {
            // if a scriptmanager present and page is in postback...
            if (this.ScriptManager != null && this.ScriptManager.IsInAsyncPostBack)
            {
                // create a new Guid...
                var errorGuid = Guid.NewGuid().ToString();

                // save error to application state...
                this.Application.Add(errorGuid, errorMessage);

                // transfer to the error page...
                this.Response.Redirect(string.Format("{0}?ErrorGUID={1}", PageType.ErrorPage.GetUrl(), errorGuid));
            }
            else
            {
                // add error message to the context ...
                HttpContext.Current.Items.Add(ErrorMessagesRes.Error_Window_Title, errorMessage);

                // redirect user to error page...
                this.Server.Transfer(PageType.ErrorPage.GetUrl());
            }
        }

We have two policies in the web.config file - a DataAccessLayerPolicy and a BusinessLayerPolicy, as follows:

  <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
    defaultCategory="Errors" logWarningsWhenNoCategoriesMatch="true">
    <listeners>
      <add name="Error Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        fileName="error.log" header="------------------Start Log------------------"
        footer="-------------------End Log-------------------" formatter="Text Formatter"
        traceOutputOptions="None" filter="All" />
    </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}&#xD;&#xA;&#xD;&#xA;           Message: {message}&#xD;&#xA;&#xD;&#xA;           Category: {category}&#xD;&#xA;&#xD;&#xA;           Priority: {priority}&#xD;&#xA;&#xD;&#xA;           EventId: {eventid}&#xD;&#xA;&#xD;&#xA;           Severity: {severity}&#xD;&#xA;&#xD;&#xA;           Title: {title}&#xD;&#xA;&#xD;&#xA;           Machine: {machine}&#xD;&#xA;&#xD;&#xA;           Application Domain: {appDomain}&#xD;&#xA;&#xD;&#xA;           Process Id: {processId}&#xD;&#xA;&#xD;&#xA;           Process Name: {processName}&#xD;&#xA;&#xD;&#xA;           Win32 Thread Id: {win32ThreadId}&#xD;&#xA;&#xD;&#xA;           Thread Name: {threadName}&#xD;&#xA;&#xD;&#xA;           Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}"
        name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="Error" name="Errors">
        <listeners>
          <add name="Error Log Listener" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events">
        <listeners>
          <add name="Error Log Listener" />
        </listeners>
      </allEvents>
      <notProcessed switchValue="All" name="Unprocessed Category">
        <listeners>
          <add name="Error Log Listener" />
        </listeners>
      </notProcessed>
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Error Log Listener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
  <exceptionHandling>
    <exceptionPolicies>
      <add name="BusinessLogicLayerPolicy">
        <exceptionTypes>
          <add name="DomainInternalMessageException" type="ALT_Shared.Exceptions.DomainInternalMessageException, ALT_Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
            postHandlingAction="ThrowNewException">
            <exceptionHandlers>
              <add name="Log Internal Message Exception" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                logCategory="Errors" eventId="201" severity="Error" title="Internal Message Exception"
                formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                priority="0" useDefaultLogger="true" />
              <add type="ALT_Shared.ExceptionHandlers.DomainInternalMessageExceptionHandler, ALT_Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                name="Internal Message Exception Handler" />
            </exceptionHandlers>
          </add>
          <add name="DomainSecurityException" type="ALT_Shared.Exceptions.DomainSecurityException, ALT_Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
            postHandlingAction="ThrowNewException">
            <exceptionHandlers>
              <add name="Log Domain Security Exception" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                logCategory="Errors" eventId="202" severity="Error" title="Domain Security Exception"
                formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                priority="0" useDefaultLogger="true" />
              <add type="ALT_Shared.ExceptionHandlers.DomainSecurityExceptionHandler, ALT_Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                name="Domain Security Exception Handler" />
            </exceptionHandlers>
          </add>
          <add name="EntityValidationException" type="ALT_Shared.Exceptions.EntityValidationException, ALT_Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
            postHandlingAction="ThrowNewException">
            <exceptionHandlers>
              <add type="ALT_Shared.ExceptionHandlers.EntityValidationExceptionHandler, ALT_Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                name="Entity Validation Exception Handler" />
            </exceptionHandlers>
          </add>
          <add name="SystemException" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="ThrowNewException">
            <exceptionHandlers>
              <add name="Log System Exception" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                logCategory="Errors" eventId="204" severity="Error" title="System Exception"
                formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                priority="0" useDefaultLogger="true" />
              <add type="ALT_Shared.ExceptionHandlers.DomainInternalMessageExceptionHandler, ALT_Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                name="Internal Message Exception Handler" />
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
      <add name="DataAccessLayerPolicy">
        <exceptionTypes>
          <add name="DomainInternalMessageException" type="ALT_Shared.Exceptions.DomainInternalMessageException, ALT_Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
            postHandlingAction="ThrowNewException">
            <exceptionHandlers>
              <add name="Log Internal Message Exception" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                logCategory="Errors" eventId="201" severity="Error" title="Internal Message Exception"
                formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                priority="0" useDefaultLogger="true" />
              <add type="ALT_Shared.ExceptionHandlers.DomainInternalMessageExceptionHandler, ALT_Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                name="Internal Message Exception Handler" />
            </exceptionHandlers>
          </add>
          <add name="DomainSecurityException" type="ALT_Shared.Exceptions.DomainSecurityException, ALT_Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
            postHandlingAction="ThrowNewException">
            <exceptionHandlers>
              <add name="Log Domain Security Exception" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                logCategory="Errors" eventId="202" severity="Error" title="Domain Security Exception"
                formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                priority="0" useDefaultLogger="true" />
              <add type="ALT_Shared.ExceptionHandlers.DomainSecurityExceptionHandler, ALT_Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                name="Domain Security Exception Handler" />
            </exceptionHandlers>
          </add>
          <add name="EntityValidationException" type="ALT_Shared.Exceptions.EntityValidationException, ALT_Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
            postHandlingAction="ThrowNewException">
            <exceptionHandlers>
              <add type="ALT_Shared.ExceptionHandlers.EntityValidationExceptionHandler, ALT_Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                name="Entity Validation Exception Handler" />
            </exceptionHandlers>
          </add>
          <add name="OptimisticConcurrencyException" type="System.Data.OptimisticConcurrencyException, System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="ThrowNewException">
            <exceptionHandlers>
              <add name="Log Optimistic Concurrency Exception" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                logCategory="Errors" eventId="205" severity="Error" title="Optimistic Concurrency Exception"
                formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                priority="0" useDefaultLogger="true" />
              <add type="ALT_Shared.ExceptionHandlers.OptimisticConcurrencyExceptionHandler, ALT_Shared, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
                name="Optimistic Concurrency Exception Handler" />
            </exceptionHandlers>
          </add>
          <add name="SqlDatabaseException" type="System.Data.SqlClient.SqlException, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="ThrowNewException">
            <exceptionHandlers>
              <add name="Log Sql Exception" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                logCategory="Errors" eventId="206" severity="Error" title="Sql Exception"
                formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                priority="0" useDefaultLogger="true" />
              <add type="ALT_Shared.ExceptionHandlers.SqlExceptionHandler, ALT_Shared, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
                name="Sql Exception Handler" />
            </exceptionHandlers>
          </add>
          <add name="SystemException" type="System.Exception, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
            postHandlingAction="ThrowNewException">
            <exceptionHandlers>
              <add name="Log System Exception" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                logCategory="Errors" eventId="204" severity="Error" title="System Exception"
                formatterType="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.TextExceptionFormatter, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                priority="0" useDefaultLogger="true" />
              <add type="ALT_Shared.ExceptionHandlers.DomainInternalMessageExceptionHandler, ALT_Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
                name="Internal Message Exception Handler" />
            </exceptionHandlers>
          </add>
        </exceptionTypes>
      </add>
    </exceptionPolicies>
  </exceptionHandling>

The page_load event for the error page redirected to in DisplayErrorPage takes the text defined in HandleExp and displays it onscreen. The details of the error are shown in the error log created by the log listerner.

In each of the manager and controller classes in the BLL and the providers classes in the DAL, we have a HandleExp method (note the call to the manager uses the appropriate policy layer as argument 2, based on whether called from the manager/controller or provider).

        protected bool HandleException(Exception exp)
        {
            // dispose context...
            this.Dispose();

            // create exception object...
            Exception exceptionToThrow;

            // handle exception in the manager...
            var value = ExceptionHandlingManager.HandleException(
                exp, ExceptionHandlingPolicyType.DataAccessLayerPolicy, out exceptionToThrow);

            // if exception handled and an error returned...
            if (value && !Utilities.IsNull(exceptionToThrow))
            {
                // throw the error...
                throw exceptionToThrow;
            }

            // return whether error was rethrown...
            return value;
        }

And the ExceptionHandlingManager is a public class which inherits from an interface.

As you can see (hopefully) from the code, with the exception of DomainInternalMessageException (with severity as Warning) and EntityValidationException, each 'sanitised' message is used for display.

I have now reverted to using the datetime as my identifier, but the error logging has now stopped working completely, i.e. the error.log file is no longer being updated.

I'm not sure where to go from here!

Martin

 

Mar 18, 2011 at 2:01 AM

Did you debug through the code and verified that inside the call to ExceptionHandlingManager.HandleException does call the ExceptionPolicy.HandleException method? 

Could you also configure a different trace listener under your Logging Errors and Warnings special category?  If an error occurs during logging there should be a log message written by that trace listener indicating what exception was encountered.

I recommend to use a different trace listener since as you said, logging to the error.log file had already stopped.

 

Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com