Search code examples
c#log4net.net-standardlog4net-configuration

How to fix CS1503 Argument 1: cannot convert from 'string' to 'System.Type'?


I have this piece of code in .net framework class library project, I want to reuse it in.net standard class library project. It works as expected, but gives compilation error in .net standard project.

public FxLogger(string logger)
{
    ILog AppLogger = LogManager.GetLogger(logger);

Error:

CS1503  Argument 1: cannot convert from 'string' to 'System.Type'

log4net version in both application 2.0.8 I can see these methods declaration in the LogManager class

public static ILog GetLogger(string repository, string name);
public static ILog GetLogger(Assembly repositoryAssembly, Type type);
public static ILog GetLogger(string repository, Type type);
public static ILog GetLogger(Type type);
public static ILog GetLogger(Assembly repositoryAssembly, string name);

Solution

  • Try

     ILog AppLogger = LogManager.GetLogger(Assembly.GetCallingAssembly(),logger);
    

    It looks like the .net framework method is defined as

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