【发布时间】:2017-01-29 07:41:33
【问题描述】:
此问题与Steven 的答案-here 有关。他提出了一个非常好的记录器包装器。我将他的代码粘贴在下面:
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.
}
所以,我的问题是创建代理 Microsoft.Extensions.Logging 的实现的正确方法是什么 以及 稍后在代码中使用它的最佳方法是什么?
注意:此问题是 this question about log4net 的副本,但现在特定于 Microsoft.Extensions.Logging。
【问题讨论】:
标签: c# .net logging microsoft-extensions-logging