我爲Asp.Net 2.0配置了log4Net EventLogAppender。但它不會記錄任何內容。我在我的Web.Config中有以下內容。log4Net EventlogAppender不適用於Asp.Net 2.0網站?
<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>
我已經創建了測試日誌事件日誌,並且AspNet用戶具有事件日誌註冊表項的權限。我也有在Global.asax Application_Start中配置的log4Net。
log4net.Config.XmlConfigurator.Configure();
更新:我打開log4net的內部調試,發現下面的錯誤在跟蹤。
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)
更新2:如果我創建使用C#一個基於控制檯的應用程序,然後使用Web應用程序的事件來源(測試網絡)這最後的作品。
您是否嘗試開啓log4net內部調試?也許這是拋出一個你通常不會看到的錯誤:http://logging.apache.org/log4net/release/faq.html – 2010-04-06 19:00:51