Log4Net on .Net Standard has no version for getting logger without repository

后端 未结 1 1277
悲&欢浪女
悲&欢浪女 2021-01-20 17:41

I am trying to move a project to .net standard and it basically is a class library. I am using log4net for logging and I was using the method

public static          


        
1条回答
  •  隐瞒了意图╮
    2021-01-20 18:20

    The implementation of GetLogger is simple:

    public static ILog GetLogger(string name)
    {
        return GetLogger(Assembly.GetCallingAssembly(), name);
    }
    

    Assuming you want to use your class library's assembly, you can write your own helper method for that easily:

    private static ILog GetLogger(string name) =>
        LogManager.GetLogger(typeof(SomeTypeInYourLibrary).Assembly, name);
    

    It's basically hard-coding the assembly to be "the assembly containing the type you've specified" which is what you'd always get from calling GetLogger(string) from your library anyway.

    0 讨论(0)
提交回复
热议问题