try { // Some code that may throw an exception } catch (Exception ex) { logger.Error(ex, "An exception occurred"); }
try { // Some code that may throw an exception } catch (Exception ex) { var properties = new DictionaryThis code block logs the captured exception with custom properties like User and Email. These properties can be used to filter and search the logs later. Overall, NLog Logger ErrorException is a useful feature of the NLog framework that makes capturing and logging exceptions easy and efficient.{ { "User", "John Doe" }, { "Email", "[email protected]" } }; logger.Error(ex, "An exception occurred", properties); }