简体   繁体   中英

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();
    }

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM