问题
I have a number of custom object renderers so that I can keep my log statements as DRY as possible. When I first deploy my app log4net doesn't recognize the custom renderers but it does do everything else correctly. If I touch the config file it (make it looked changed) the file watcher picks up the change and the renderers start working. However after a time they stop working again and I have to touch the log4net config file again.
The setup is a .Net 3.5 (sp1) wcf application. The problem occurs in both the vs 2008 development web server and on IIS 7 on win 2008. I have a config file called log4net.config and I'm using the AssemblyInfo method for point at it.
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
The way I access a logger is through the use of static members on the class like so.
private static readonly ILog log = LogManager.GetLogger(typeof(Service));
The renderers are configured similar to this.
<renderer renderingClass="MyCompany.Log4net.SearchRequestRenderer, MyCompany.Log4net" renderedClass="System.DirectoryServices.Protocols.SearchRequest" />
These renderers are all in a separate assembly from the main where the logging is taking place. Am I missing something or doing something wrong? I don't know why it doesn't recognize the renderers right away and then forgets them again later.
回答1:
I found the answer. I had to include more of the assembly information for the rendered class.
<renderer renderingClass="MyCompany.Log4net.SearchRequestRenderer, MyCompany.Log4net" renderedClass="System.DirectoryServices.Protocols.SearchRequest" />
Became
<renderer renderingClass="MyCompany.Log4net.SearchRequestRenderer, MyCompany.Log4net" renderedClass="System.DirectoryServices.Protocols.SearchRequest, System.DirectoryServices.Protocols, Version=2.0.0.0 , Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
来源:https://stackoverflow.com/questions/7045316/log4net-stops-using-custom-renderers