A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/NLog/NLog/wiki/Exception-Layout-Renderer below:

Exception layout renderer · NLog/NLog Wiki · GitHub

Exception information provided together with the LogEvent. See also How to properly log exceptions.

Platforms Supported: All

${exception:format=String:innerFormat=String:maxInnerExceptionLevel=Integer:innerExceptionSeparator=String
           :separator=String:exceptionDataSeparator=string}

If debug symbol information is not available, then Exception.ToString() will not output source-code filenames or line-numbers. Symbol information from PDB files must be deployed with the application to retrieve and output source-code line-number. For applications compiled in release mode, then inlining can occur and cause "unexpected" line-numbers.

${exception:format=message}

ToString will also print the innerException:

${exception:format=toString}
Log full (including Data)

Also print exception data, e.g.

var ex = new Exception();
ex.Data.Add("data1", "val2");
throw ex;
${exception:format=toString,Data}

the @ format recursively serializes the entire exception hierarchy; combining it with maxInnerExceptionLevel and innerExceptionSeparator won't do what you want. To get the entire exception hierarchy including innerexceptions as nested objects, just specify :format=@.

Custom Exception Serialization

NLog 4.7 allows you to override the object reflection for certain object-types. This can be useful for objects with dangerous properties or complex properties.

LogManager.Setup().SetupSerialization(s =>
   s.RegisterObjectTransformation<System.Net.WebException>(ex => new {
      Type = ex.GetType().ToString(),
      Message = ex.Message,
      StackTrace = ex.StackTrace,
      Source = ex.Source,
      InnerException = ex.InnerException,
      Status = ex.Status,
      Response = ex.Response.ToString(),  // Call your custom method to render stream as string
   })
);

This can then be used together with:

${exception:format=ToString,Properties,Data}

Or like this for generating JSON:


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4