我正在将一个项目移植到.Net Core,我想使用log4net登录.net核心。我在.NET代码:.net核心log4net静态日志字段
private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
在.NET的核心问题是 “methodbase不包含定义getCurrentMethod()”
我想这应该工作(不是100%肯定):
private static readonly ILog log = LogManager.GetLogger(typeof("MyClassName")) ;
但我想要的东西,可以复制/粘贴到任何类,而不必关心类名...任何人都知道的东西是行得通的?
首先不要复制,但使用依赖注入? – CodeCaster
CodeCaster说什么,但看看这里https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging – DavidG
值得注意的是,你的原始代码[应该在.NET标准2下正常工作](https ://github.com/dotnet/corefx/issues/12496) –