Exception are swallowed even if throwExceptions = true with LogReceiverService

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

Exception are swallowed even if throwExceptions = true with LogReceiverService


Context: We have implemented a WCF LogReceiverService instance which is adressed by a client application.
Logging features are important requirements in the scope of our application As consequence, we want to detect if the Logger Service faces troubles and especially if it is unreachable.For this reason, we set throwExceptions = true in the client Nlog.config file to be informed when internal exception occured in NLog.

Problem: When the endPointAdress is wrong in the client application or if the Logger Service is not running., no exception is raised to the client application. For the client point of view, everthing is going as the log was successfully sent to the WCF Logger Service.

Investigation: I downloaded the source code version and debug my client application to learn more. I got effectively an EndpointNotFoundException in WcfLogReceiverClient.EndProcessLogMessages(IAsyncResult result). So i search further why the exception is swallowed. I think, I found the reason. The problem is inside LoggerImpl.Write(...) in the exceptionHandler passed to the WriteToTargetWithFilterChain() call.
Here is the exceptionHandler specified in the code:

AsyncContinuation exceptionHandler = ex =>
      if (ex != null)
           if (factory.ThrowExceptions && Thread.CurrentThread.ManagedThreadId == originalThreadId)
                throw new NLogRuntimeException("Exception occurred in NLog", ex);

Thread.CurrentThread.ManagedThreadId == originalThreadId, is always false

Question: I presume the fact the Threads Id's are different is due to the internal behavior of WCF. So, my question is... Do you have any suggestion to correct/improve this and insure the NLogRuntimeException is thrown ?

Thank you for your help.