log4net 和 Sharepoint 2007 工作流程
我正在开发一个包含一些自定义 Sharepoint 工作流组件的项目,我想将 log4net 添加到其中。
我真的很难让 log4net 输出任何东西!
这是我当前的设置:
在我的工作流程的代码隐藏中:
private ILog log;
public MessageQueueWorkflow()
{
InitializeComponent();
string filepath = ConfigurationManager.AppSettings["log4netConfigPath"];
if (!string.IsNullOrEmpty(filepath))
{
log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(filepath));
log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
}
}
public Guid workflowId = default(System.Guid);
public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();
private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
{
try
{
#region Logging
if (log.IsDebugEnabled)
{
log.Debug(System.Reflection.MethodInfo.GetCurrentMethod().Name);
}
#endregion Logging
// do some stuff
}
catch (Exception ex)
{
if (log.IsErrorEnabled)
{
log.Error("An error has occurred.", ex);
}
throw ex;
}
}
在 Sharepoint 站点的 web.config 中:
<appSettings>
<add key="log4netConfigPath" value="C:\Inetpub\wwwroot\wss\VirtualDirectories\80\log4net.config"/>
</appSettings>
在我的 log4net.config 文件中:
<log4net debug="true">
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
<applicationName value="MyApp" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d %-5p %c - %m%n" />
</layout>
</appender>
</log4net>
现在,当我运行此工作流程时,我希望看到一些调试条目显示在EventViewer,但我什么也没得到。
有什么想法我做错了吗?
谢谢!
I'm working on a project with some custom Sharepoint Workflow components which I'd like to add log4net to.
I'm really struggling to get log4net to output anything at all though!
Here's my current setup:
In the codebehind for my Workflow:
private ILog log;
public MessageQueueWorkflow()
{
InitializeComponent();
string filepath = ConfigurationManager.AppSettings["log4netConfigPath"];
if (!string.IsNullOrEmpty(filepath))
{
log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(filepath));
log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
}
}
public Guid workflowId = default(System.Guid);
public SPWorkflowActivationProperties workflowProperties = new SPWorkflowActivationProperties();
private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
{
try
{
#region Logging
if (log.IsDebugEnabled)
{
log.Debug(System.Reflection.MethodInfo.GetCurrentMethod().Name);
}
#endregion Logging
// do some stuff
}
catch (Exception ex)
{
if (log.IsErrorEnabled)
{
log.Error("An error has occurred.", ex);
}
throw ex;
}
}
In my web.config for the Sharepoint site:
<appSettings>
<add key="log4netConfigPath" value="C:\Inetpub\wwwroot\wss\VirtualDirectories\80\log4net.config"/>
</appSettings>
In my log4net.config file:
<log4net debug="true">
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
<applicationName value="MyApp" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d %-5p %c - %m%n" />
</layout>
</appender>
</log4net>
Now, when I run this workflow, I'd expect to see some debug entries showing up in the EventViewer, but I'm getting nothing.
Any ideas what I'm doing wrong?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要配置至少一个记录器。通常您会配置根记录器。例如:
如果这还不能使其工作,我建议您配置一个跟踪侦听器来输出 log4net 内部调试消息。 (您已经打开了内部调试。)
You need to configure at least one logger. Usually you would configure the root logger. E.g.:
If this is not making it work yet, the I recommend that you configure a trace listener that will output the log4net internal debugging messages. (You already have internal debugging turned on.)
另请记住,当工作流进入睡眠状态(序列化到数据库)并唤醒时,它会继续在 OWSTIMER.EXE 进程中运行,您将不再看到任何日志条目。这也适用于事件接收器中写入的日志条目或 stsadm 或除 IIS 工作进程之外的任何其他进程执行的方法。
所以我建议您:
然后我更喜欢将其放入我的 AssemblyInfo.cs 中:
因此,无论进程将使用我的程序集,它都会被记录(它是事件吗?接收器、stsadm 控制台或 SharePoint 管理器 - 全部都会被记录)。
请参阅 SharePoint 和 Log4Net 问题。
Also keep in mind that whenver workflow goes to sleep (serialized to database) and wakes up, it continues to run within OWSTIMER.EXE process and you will NO MORE see any log entries. This also applies for log entries written in event reciever or methods executed by stsadm or any other process than IIS worker process.
So i would recommend you to:
Then i prefer putting this in my AssemblyInfo.cs:
So whatever process will use my assembly, it will get logged (would it be event reciever, stsadm console or SharePoint Manager - it all gets logged).
See SharePoint and Log4Net question.