I'm implementing the ILogger interface and using MEF to resolve the dependency. Unfortunately, when raising an exception in my controller I'm hitting the LogException method three times, resulting in multiple entries in the event log.
The stack traces are roughly as follows:
First entry into LogException
HttpControllerDispatcher.SendAsyncInternal
-> (methods including ApiController.InvokeActionWithExceptionFilters and ApiController.InvokeActionWithActionFilters)
-> ILogger.LogException
Second entry into LogException
HttpControllerDispatcher.SendAsyncInternal
-> (methods including ApiController.InvokeActionWithExceptionFilters)
-> ILogger.LogException
Third entry into LogException
HttpControllerDispatcher.SendAsyncInternal
-> (no ApiController methods)
-> ILogger.LogException
I'm actually using an ExceptionFilterAttribute to provide additional information that is used by the logging, and this filter isn't invoked until just before the final call to LogException.
Is this the expected behaviour? If so, is there a way to avoid writing anything to the log during the first two calls to LogException?
Thanks in advance for any guidance; let me know if you need to see any code...
JackWhelpton
0 Points
1 Post
Implementing ILogger: LogException called repeatedly
Feb 22, 2012 10:17 AM|LINK
I'm implementing the ILogger interface and using MEF to resolve the dependency. Unfortunately, when raising an exception in my controller I'm hitting the LogException method three times, resulting in multiple entries in the event log.
The stack traces are roughly as follows:
First entry into LogException
HttpControllerDispatcher.SendAsyncInternal
-> (methods including ApiController.InvokeActionWithExceptionFilters and ApiController.InvokeActionWithActionFilters)
-> ILogger.LogException
Second entry into LogException
HttpControllerDispatcher.SendAsyncInternal
-> (methods including ApiController.InvokeActionWithExceptionFilters)
-> ILogger.LogException
Third entry into LogException
HttpControllerDispatcher.SendAsyncInternal
-> (no ApiController methods)
-> ILogger.LogException
I'm actually using an ExceptionFilterAttribute to provide additional information that is used by the logging, and this filter isn't invoked until just before the final call to LogException.
Is this the expected behaviour? If so, is there a way to avoid writing anything to the log during the first two calls to LogException?
Thanks in advance for any guidance; let me know if you need to see any code...