Log4net 停止使用自定义渲染器

发布于 2024-11-29 08:36:27 字数 844 浏览 2 评论 0原文

我有许多自定义对象渲染器,以便我可以使日志语句尽可能保持干燥。当我第一次部署我的应用程序时,log4net 无法识别自定义渲染器,但它确实可以正确执行其他所有操作。如果我触摸配置文件(使其看起来发生了变化),文件观察器就会拾取更改并且渲染器开始工作。然而,过了一段时间,他们再次停止工作,我必须再次触摸 log4net 配置文件。

该设置是一个 .Net 3.5 (sp1) wcf 应用程序。该问题出现在 vs 2008 开发 Web 服务器和 win 2008 上的 IIS 7 中。我有一个名为 log4net.config 的配置文件,我使用 AssemblyInfo 方法来指向它。

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]

我访问记录器的方式是通过在类上使用静态成员,如下所示。

private static readonly ILog log = LogManager.GetLogger(typeof(Service));

渲染器的配置与此类似。

<renderer renderingClass="MyCompany.Log4net.SearchRequestRenderer, MyCompany.Log4net" renderedClass="System.DirectoryServices.Protocols.SearchRequest" />

这些渲染器都位于与进行日志记录的主程序独立的程序集中。我错过了什么或者做错了什么吗?我不知道为什么它不能立即识别渲染器,然后又忘记它们。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心碎无痕… 2024-12-06 08:36:27

我找到了答案。我必须为渲染的类包含更多的程序集信息。

<renderer renderingClass="MyCompany.Log4net.SearchRequestRenderer, MyCompany.Log4net" renderedClass="System.DirectoryServices.Protocols.SearchRequest" />

成为

<renderer renderingClass="MyCompany.Log4net.SearchRequestRenderer, MyCompany.Log4net" renderedClass="System.DirectoryServices.Protocols.SearchRequest, System.DirectoryServices.Protocols, Version=2.0.0.0 , Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 

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" /> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文