Null Reference
Null Reference

Reputation: 11360

log4net in WCF service hosted on a windows service

I have a WCF service which is hosted on a windows service.

Where should I put XmlConfigurator.Configure();?

In other applications, I can place it in Application_Start()

Can I place this in the OnStart() method of my windows service? Will I then able to instantiate the logger from my WCF service?

This is how I instantiate my logger:

private readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

This is what I have in my windows service

    protected override void OnStart(string[] args)
    {
        if (AgentServiceHost != null)
        {
            AgentServiceHost.Close();
        }

        AgentServiceHost = new ServiceHost(typeof(CustoemrService));
        AgentServiceHost.Open();
    }

Upvotes: 0

Views: 1872

Answers (1)

Oscar
Oscar

Reputation: 13990

Just put this piece of code in your AssemblyInfo.cs file:

[assembly: log4net.Config.XmlConfigurator(Watch=true)]

http://logging.apache.org/log4net/release/manual/configuration.html

Upvotes: 3

Related Questions