Kimi
Kimi

Reputation: 14109

log4net generic type loggers on WCF Windows Service

Does anyone know why log4net would initialise loggers differently when WCF process is a console app and when it is a Windows Service?

public class GenericType<T> : where T : class
{
    public GenericType()
    {
        log = LogManager.GetLogger("Namespace.MyLogger");
    }
}

in console app the logger is "MyLogger", in windows service it is "GenericType`1".

It seems that in windows service log4net enforces something like:

log = LogManager.GetLogger(GetType());

The processes are started using this code:

static class Program
{
    static void Main(params string[] parameters)
    {           
        var service = new Service();
        if (parameters.Length > 0 && parameters[0].ToLower() == "/c")
        {
            service.RunConsole();//Calls service.OnStart()
        }
        else
        {
            ServiceBase.Run(service);
        }

    }
}

So if we run it as a console we pass "/c" argument. When we run it as a Win service, it is instaleld as a service and is executed without "/c". This is the only difference, so type loading is identical.

Non generic loggers are initialised just fine.

EDIT:

Simplified exapmple

Upvotes: 0

Views: 876

Answers (1)

Davide Piras
Davide Piras

Reputation: 44605

I think the behaviour you describe is related to the availability of your types in the calling application, this depends on the way you reference the object T and the way you expose it as data contract or via shared class libraries like core or interfaces...

Can you explain more about your architecture and c# projects stack?

Log4Net has no issue in this, is more an issue on how the type name is resolved from different consumers.

Upvotes: 1

Related Questions