EventId Not Showing in Logs
Opened this issue · 0 comments
MDornian commented
Even when eventId
is provided, the pattern %property{eventId}
will always produce (null)
in the logs.
To reproduce this problem, I modified the following file: samples\Net8.0\WebApi\Controllers\WeatherForecastController
.
// Added the following 2 lines
EventId eventId = 1001;
_logger.LogWarning(eventId, "Sample with EventId");
_logger.LogCritical(new Exception("ExceptionText"), "This is {weather}", weatherForecasts.First().Summary);
_logger.LogTrace("Weather forecast ready!");
This produced the following log entry
2024-03-05 11:11:28,910 WARN Sample.WebApi.Net80.Controllers.WeatherForecastController.Get [(null)] [32] - MESSAGE: Sample with EventId
I would have expected
2024-03-05 11:11:28,910 WARN Sample.WebApi.Net80.Controllers.WeatherForecastController.Get [1001] [32] - MESSAGE: Sample with EventId
Just a reminder that the log4net.config
has the following conversion pattern
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %5level %logger.%method [%property{eventId}] [%line] - MESSAGE: %message%newline %exception" />
</layout>