.Net Standard上的Log4Net没有用于获取没有存储库的记录器的版本

Joh*_*iou 2 c# log4net .net-standard

我正在尝试将项目移至.net标准,它基本上是一个类库。我正在使用log4net进行日志记录,并且正在使用该方法

public static ILog GetLogger(string name);
Run Code Online (Sandbox Code Playgroud)

由于这是一个由多个项目引用的库,因此不应定义存储库,因为每个项目都引用该库,而是定义它自己的记录库。移植到.Net标准时,如何解决此问题?

Jon*_*eet 10

的实现GetLogger很简单:

public static ILog GetLogger(string name)
{
    return GetLogger(Assembly.GetCallingAssembly(), name);
}
Run Code Online (Sandbox Code Playgroud)

假设您要使用类库的程序集,则可以轻松地为此编写自己的帮助程序方法:

private static ILog GetLogger(string name) =>
    LogManager.GetLogger(typeof(SomeTypeInYourLibrary).Assembly, name);
Run Code Online (Sandbox Code Playgroud)

基本上,将程序集硬编码为“包含指定类型的程序集”,这是GetLogger(string)无论如何从库中调用总会得到的结果。