SharePoint 和 Log4Net [英] SharePoint and Log4Net

查看:26
本文介绍了SharePoint 和 Log4Net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找将 log4net 集成到 SharePoint 以进行 Web 请求、功能激活和所有计时器内容的最佳实践.

I'm looking for best practices to integrate log4net to SharePoint for web request, feature activation and all timer stuff.

我的农场中有几个子项目,我只想拥有一个 Log4Net.config 文件.

I have several subprojects in my farm, and I would like to have only one Log4Net.config file.


我不仅需要为web应用程序配置log4net,这很容易(我使用global.asax,和一个log4net.config文件,这样我就可以在不重新加载webapp的情况下修改日志设置),而且我还需要异步日志事件:


Not only I need to configure log4net for the web application, which is easy to do (I use global.asax, and a log4net.config file, so I can modify log settings withtout reloading the webapp), but I also need to log asynchronous events:

  • 事件处理程序(如 ItemAdded)
  • 计时器工作
  • ...

推荐答案

我最近实施了这个并想出了一个对我有用的解决方案.

I implemented this recently and came up with a solution that worked for me.

使用全局范围的解决方案将您的 log4net 配置文件部署到 12 hive,并将 log4net dll 部署到 GAC.然后在您的应用程序代码中从全局文件的位置显式初始化 log4net.这允许您记录功能接收器、计时器作业和 Web 应用程序代码.

Deploy your log4net config file to the 12 hive and the log4net dll into the GAC using a globally scoped solution. Then in your application code explicitly initialize log4net from the location of your global file. This allows you to log feature receiver, timer jobs and web application code.

[assembly: log4net.Config.XmlConfigurator(ConfigFile = 
    @"C:Program FilesCommon FilesMicrosoft Shared" + 
    @"Web Server Extensions12CONFIGlog4net.config", Watch = true)]

请参阅此处http://www.codeproject.com/KB/sharepoint/SharepointLog4Net.aspx

这篇关于SharePoint 和 Log4Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆