log4net 和 Sharepoint 2007 工作流程

发布于 2024-09-18 09:05:18 字数 1863 浏览 4 评论 0原文

我正在开发一个包含一些自定义 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 技术交流群。

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

发布评论

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

评论(2

抚你发端 2024-09-25 09:05:18

您需要配置至少一个记录器。通常您会配置根记录器。例如:

<log4net>
   ...
   <root>
       <level value="ALL" />
      <appender-ref ref="EventLogAppender" />     
   </root>
</log4net>

如果这还不能使其工作,我建议您配置一个跟踪侦听器来输出 log4net 内部调试消息。 (您已经打开了内部调试。)

You need to configure at least one logger. Usually you would configure the root logger. E.g.:

<log4net>
   ...
   <root>
       <level value="ALL" />
      <appender-ref ref="EventLogAppender" />     
   </root>
</log4net>

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.)

吹泡泡o 2024-09-25 09:05:18

另请记住,当工作流进入睡眠状态(序列化到数据库)并唤醒时,它会继续在 OWSTIMER.EXE 进程中运行,您将不再看到任何日志条目。这也适用于事件接收器中写入的日志条目或 stsadm 或除 IIS 工作进程之外的任何其他进程执行的方法。

所以我建议您:

  • 将 log4net.config 放入 12Hive/CONFIG 目录
  • 将 log4net.dll 放入 GAC

然后我更喜欢将其放入我的 AssemblyInfo.cs 中:

[assembly: log4net.Config.XmlConfigurator(ConfigFile = 
    @"C:\Program Files\Common Files\Microsoft Shared\" + 
    @"Web Server Extensions\12\CONFIG\log4net.config", Watch = true)]

因此,无论进程将使用我的程序集,它都会被记录(它是事件吗?接收器、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:

  • Put log4net.config in 12Hive/CONFIG directory
  • Put log4net.dll in GAC

Then i prefer putting this in my AssemblyInfo.cs:

[assembly: log4net.Config.XmlConfigurator(ConfigFile = 
    @"C:\Program Files\Common Files\Microsoft Shared\" + 
    @"Web Server Extensions\12\CONFIG\log4net.config", Watch = true)]

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.

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