I am looking for a way to record expressive messages when I catch an exception with NLog 2.0.1, something like
try { .... } catch(Exception ex) { logger.ErrorException("Error with query {0}", query, ex); }
But NLog does not support it. Other forms that happened to me
logger.ErrorException( String.Format("Error with query {0}", query)) , ex);
or
logger.Error("Error with query {0} {1} {2}", query, ex.Message, ex.StackTrace);
or
logger.Error("Error with query {0}", query); logger.ErrorException("", ex);
or
LogEventInfo ei = new LogEventInfo(LogLevel.Error, logger.Name, null, "Error with query {0}", new object[] { query }, ex); logger.Log(ei);
But no one seems as simple as calling logger.Error () At the moment, the first option is my support, despite the formatting of the string, which may not be used:
- The second option does not use layout options to exclude .
- the third one creates two journal entries and can be confusing.
- The fourth option is much less clear.
Is there a few more?
source share