I'm using the ASP.NET Core logger along with NLog. When I log an error/critical with an exception, the message is logged but the exception doesn't.
try
{
// my code throws an exception
}
catch (Exception ex)
{
_logger.LogError($"There was an error", ex);
return null;
}
My NLog configuration looks like this:
<target xsi:type="File" name="ApiLogger" fileName="Logs\api-${shortdate}.log"
layout="${longdate} - ${uppercase:${level}} - ${threadid} - ${logger} - ${message} ${exception:innerFormat=Message,StackTrace}" />
Whats logged in the file is There was an error
without the actual exception and stacktrace.