0

this code:

try
{
    ...
    ...
}
catch (Exception ex)
{
    logger.Error(ex);                       // v1
    
    logger.Error(ex.ToString);              // v2
    
    logger.Error(ex.ToString());            // v3
    
    logger.Error("Message: " + ex);         // v4
}

Will not log full stack trace in v1 scenario. Instead - only message will be logged. I think this is weird. Why there is a difference between ex, and ex.ToString()? I thought, that using ex should be the same as ex.ToString() in logging.

dafie
  • 951
  • 7
  • 25
  • `${message}` will give the log-message or basic exception-details. `${exception:format=tostring}` will output all exception-details. NLog v5 default layout uses `${message:withexception=true}` which gives you both details. See also https://github.com/nlog/NLog/wiki/How-to-log-exceptions – Rolf Kristensen Mar 15 '23 at 18:00

0 Answers0