Sharepoint计时器作业和log4net [英] Sharepoint Timer Job and log4net

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

问题描述

我正在开发一个自定义SharePoint解决方案,该解决方案由功能和计时器作业(由FeatureActivated中的功能创建)组成. 在我的解决方案中,我想使用log4net进行日志记录(我了解ULS).

I'm developing a custom SharePoint solution which consist of a feature and a timer job (which is created by the feature in FeatureActivated). In my solution I want to use log4net for logging (I know about ULS).

该功能本身中的log4net一切都很好(只是将log4net.config放在web.config附近,一切都很好),但是我完全不知道如何从计时器作业中初始化log4net(考虑到它不是通过运行的IIS,但OSWTIMER).

Everything is fine with log4net in the feature itself (just placed log4net.config near web.config and all is fine), but I have completely no idea how to initialize log4net from timer job (taking into account it is run not by IIS but by OSWTIMER).

有人可以帮我找到问题的答案吗?

Can someone please help me finding answers for the questions:

  1. 将log4net.config存储在何处以及如何将其传递给作业?
  2. 每次调用Execute()方法时是否需要初始化log4net?

谢谢!

推荐答案

自从我使用log4net以来已经有一段时间了,但是如果我没记错的话,您可以将配置文件存储在任何您想要的位置,然后让log4net从那里加载它在记录器初始化期间.

It has been a while ago since I used log4net but if I remember right, you could store you configuration file where ever you want and let log4net load it from there during initialization of the logger.

1)一个存储配置文件的好地方是12个配置单元中的文件夹.也许是您功能的文件夹.由于此文件的路径不会更改,因此应该易于使用记录器进行引用.

1) A good place to store the configuration file would be the folder within the 12 hives. Perhaps the folder of your feature. As the path to this file won't change it should be easy to reference it with the logger.

2)我认为您每次必须将记录器初始化为 SPJobDefinition (计时器作业类)在不运行时存储在数据库中.将计时器作业存储在数据库中的功能来自SPJobDefinition的基类

2) I think you'll have to initialize the logger every time as the SPJobDefinition (timer job class) is stored within the database when it doesn't run. The functionality to store the timer job in the database comes from the SPJobDefinition's base class SPPersistedObject. Member variables of a class inherited from SPPersistedObject, that should be stored together with the class in the database, have to be marked with a [Persisted] attribute. But as far as I know persisted objects can only be elementary data types (int, long, string, ...).

因此,在数据库中存储log4net Logger对象将不起作用,或者至少不被支持.因此,每次从数据库加载作业时,都必须再次初始化Logger对象.

So storing a log4net Logger object within the database won't work or at least is not supported. So every time your job is loaded from the database the Logger object has to be initialized again.

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

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