log4Net EventlogAppender不适用于Asp.Net 2.0 WebSite? [英] log4Net EventlogAppender does not work for Asp.Net 2.0 WebSite?

查看:188
本文介绍了log4Net EventlogAppender不适用于Asp.Net 2.0 WebSite?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为Asp.Net 2.0配置了log4Net EventLogAppender。但是它不记录任何东西。我在我的Web.Config中有以下内容。

 < log4net> 
< appender name =EventLogAppendertype =log4net.Appender.EventLogAppender>
< param name =LogNamevalue =测试日志/>
< param name =ApplicationNamevalue =Test-Web/>
< layout type =log4net.Layout.PatternLayout>
< conversionPattern value =%date [%thread]%-5level%logger [%property {NDC}] - %message%newline/>
< / layout>
< / appender>
< root>
< priority value =ERROR/>
< appender-ref ref =EventLogAppender/>
< / root>
< logger name =NHibernate>
< level value =ERROR/>
< appender-ref ref =EventLogAppender/>
< / logger>
< / log4net>

我已经创建了测试日志事件日志,AspNet用户具有事件日志注册表项的权限。我还在Global.asax Application_Start中配置了log4Net。

  log4net.Config.XmlConfigurator.Configure(); 

更新:我打开了log4net内部调试,发现以下错误在跟踪中。

  log4net:ERROR XmlHierarchyConfigurator:无法创建类型为[log4net.Appender.EventLogAppender]的Appender [EventLogAppender]。报告错误如下。 
System.Security.SecurityException:未找到源,但无法搜索某些或所有事件日志。无法访问的日志:安全。
在System.Diagnostics.EventLog.FindSourceRegistration(String source,String machineName,Boolean readOnly)
在System.Diagnostics.EventLog.SourceExists(String source,String machineName)
在System.Diagnostics。 EventLog.SourceExists(String source)
at log4net.Appender.EventLogAppender.ActivateOptions()
at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)

更新2 :如果我在c#中使用基于控制台的应用程序创建事件源(Test-Web)然后使用Web应用程序。

解决方案

我不能准确地告诉你可能是什么错,但如果你去这里,你会请参阅如何启用log4net内部调试?在底部的方式。如果出现错误,Log4net将不会抛出异常,因此您必须启用内部调试才能从log4net获取信息。



http://logging.apache.org/log4net/release/faq.html



编辑:另请参阅使用EventLogAppender解释潜在挂起的问题。


I have configured log4Net EventLogAppender for Asp.Net 2.0. However it does not log anything. I have following in my Web.Config.

<log4net>
    <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
      <param name="LogName" value="Test Log" />
      <param name="ApplicationName" value="Test-Web" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
      </layout>
    </appender>
    <root>
      <priority value="ERROR"/>
      <appender-ref ref="EventLogAppender"/>
    </root>
    <logger name="NHibernate">
      <level value="ERROR" />
      <appender-ref ref="EventLogAppender" />
    </logger>
  </log4net>

I already have Test-Log Event Log created and AspNet user has permission on the Event Log registry entry. I also have log4Net configured in Global.asax Application_Start.

log4net.Config.XmlConfigurator.Configure();

Update : I switched on the log4net internal debugging and found the following error in the trace.

log4net:ERROR XmlHierarchyConfigurator: Could not create Appender [EventLogAppender] of type [log4net.Appender.EventLogAppender]. Reported error follows.
System.Security.SecurityException: The source was not found, but some or all event logs could not be searched.  Inaccessible logs: Security.
   at System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly)
   at System.Diagnostics.EventLog.SourceExists(String source, String machineName)
   at System.Diagnostics.EventLog.SourceExists(String source)
   at log4net.Appender.EventLogAppender.ActivateOptions()
   at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)

Update 2 : It finally works if I create the Event Source (Test-Web) using a console based application in c# and then using the Web Application.

解决方案

I can't tell you exactly what might be wrong, but if you go here you will see "How do I enable log4net internal debugging?" way down at the bottom. Log4net will not throw exceptions if something is wrong, so you must enable internal debugging in order to get information from log4net.

http://logging.apache.org/log4net/release/faq.html

Edit: Also see the quesiton directly after that one that explains potential hangups with using the EventLogAppender.

这篇关于log4Net EventlogAppender不适用于Asp.Net 2.0 WebSite?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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