Skip to content

Latest commit

 

History

History
54 lines (35 loc) · 1.74 KB

README.md

File metadata and controls

54 lines (35 loc) · 1.74 KB

NLog.DemystifiedExceptions NuGet Pre Release

Improve your productivity - log clean, easy to understand exception stack traces using @benaadams's Demystifier.

Installation

Install from NuGet:

Install-Package NLog.DemystifiedExceptions

You should not need to make any changes to the NLog configuration file for your application. The package will override NLog's built-in ${exception} layout renderer automatically.

Troubleshooting

Configuration

NLog should automatically detect and load the NLog.DemystifiedExceptions.dll assembly as required.

If you have a scenario where this does not happen, you may have to register the package manually:

using NLog.LayoutRenderers;

LayoutRenderer.Register<DemystifiedExceptionLayoutRenderer>("exception");

Duplicate Exceptions Logged

Using the following code to log an exception will cause the exception to be logged twice:

logger.Error(ex);

This happens because NLog will use the original exception stack trace for ${message} and the demystified version for ${exception} when you have this kind of configuration:

  <targets>
    <target xsi:type="ColoredConsole" name="console" layout="${longdate} ${uppercase:${level}} ${message} ${exception:format=tostring} "/>
  </targets>

To avoid the duplicates, always pass a message string, even if it is empty:

logger.Error(ex, string.Empty);

Credits

Implementation based on discussions in the NLog issue tracker: NLog/NLog#2159

With thanks to everybody involved!