.Net Standard 上的 Log4Net 没有用于在没有存储库的情况下获取记录器的版本
Log4Net on .Net Standard has no version for getting logger without repository
我正在尝试将项目移动到 .net 标准,它基本上是一个 class 库。
我正在使用 log4net 进行日志记录,并且我正在使用方法
public static ILog GetLogger(string name);
由于这是一个被多个项目引用的库,因此不应定义存储库,因为每个引用该项目的项目都定义了自己的日志存储库。
在移植到 .Net 标准时如何避免这个问题?
GetLogger
的实现很简单:
public static ILog GetLogger(string name)
{
return GetLogger(Assembly.GetCallingAssembly(), name);
}
假设您想使用 class 库的程序集,您可以轻松地为此编写自己的辅助方法:
private static ILog GetLogger(string name) =>
LogManager.GetLogger(typeof(SomeTypeInYourLibrary).Assembly, name);
它基本上是将程序集硬编码为 "the assembly containing the type you've specified",无论如何从您的库中调用 GetLogger(string)
总能得到。
我正在尝试将项目移动到 .net 标准,它基本上是一个 class 库。 我正在使用 log4net 进行日志记录,并且我正在使用方法
public static ILog GetLogger(string name);
由于这是一个被多个项目引用的库,因此不应定义存储库,因为每个引用该项目的项目都定义了自己的日志存储库。 在移植到 .Net 标准时如何避免这个问题?
GetLogger
的实现很简单:
public static ILog GetLogger(string name)
{
return GetLogger(Assembly.GetCallingAssembly(), name);
}
假设您想使用 class 库的程序集,您可以轻松地为此编写自己的辅助方法:
private static ILog GetLogger(string name) =>
LogManager.GetLogger(typeof(SomeTypeInYourLibrary).Assembly, name);
它基本上是将程序集硬编码为 "the assembly containing the type you've specified",无论如何从您的库中调用 GetLogger(string)
总能得到。