This question is related to Steven’s answer - here. He proposed a very good logger wrapper. I will paste his code below:
public interface ILogger
{
void Log(LogEntry entry);
}
public static class LoggerExtensions
{
public static void Log(this ILogger logger, string message)
{
logger.Log(new LogEntry(LoggingEventType.Information,
message, null));
}
public static void Log(this ILogger logger, Exception exception)
{
logger.Log(new LogEntry(LoggingEventType.Error,
exception.Message, exception));
}
// More methods here.
}
So, my question is what is the proper way to create implementation that proxies to Serilog?
Note: this question is related to this question about log4net but now specific to Serilog.
exception.Messagethrough as the message is suboptimal with Serilog; instead, if you have to deal with events without a message of their own, use a constant message template like{ExceptionMessage}and parameterize it withexception.Message. This avoids attempting to parse the message as a template, and won't pollute the internal message template cache. Cheers! - Nicholas Blumhardt