How to configure log4net for WCF

前端 未结 3 603
离开以前
离开以前 2021-01-11 12:36

On my asp webforms app I would do the log4net initialization;

log4net.Config.XmlConfigurator.Configure();

on global.asax on Application_Sta

相关标签:
3条回答
  • 2021-01-11 13:05

    Adding:

    XmlConfigurator.Configure();
    

    to the constructor of each of service classes did the trick for me.

    0 讨论(0)
  • 2021-01-11 13:06

    I usually do this in the constructor of my service class, but I check if log4net is already configured:

    if (!LogManager.GetRepository().Configured)  
    {  
      // configure log4net...  
    } 
    

    I think if you really want to avoid this you would have to write your own service factory and perform the configuration there.

    0 讨论(0)
  • 2021-01-11 13:13

    Same thing: Application_Start. After all it is an ASP.NET application. For self hosting services you could configure log4net just before starting the host.

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