log4net无法在其他计算机上运行

时间:2015-04-22 19:08:36

标签: vb.net web-services logging log4net

我创建了一个Web服务项目,它使用Log4Net登录到事件查看器,也可以选择登录.log文件。一切都在我的机器上运行良好,当我尝试将其部署在另一台机器上时,它甚至无法登录到文本文件或事件查看器。事实上,它甚至没有写入文本文件,这让我觉得它无法找到log4net.dll或其他东西吗?

我在global.asax中点击下面的注释行时也收到错误消息:

log4net:错误XmlConfigurator:找不到配置部分' log4net'在应用程序的.config文件中。检查.config文件中的和元素。配置部分应如下所示:

  

部分名称=" log4net"类型=" log4net.Config.Log4NetConfigurationSectionHandler,log4net的" /

我很难过,我不知道为什么这不起作用,帮助!

从以下代码编译的exe编译器,将源添加到Windows中的事件日志,就像我说的,在我的机器上工作正常:

Option Explicit On
Option Strict On

Imports System
Imports System.Diagnostics
Imports System.Threading

Module Module1

Sub Main()

    If Not EventLog.SourceExists("LendingService") Then
                    EventLog.CreateEventSource("LendingService", "Application")
        Console.WriteLine("Creating Event Source: LendingService")
    Else
        Console.WriteLine("LendingService events already defined to this system.")
    End If

      End Sub

结束模块

的Web.config:

<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="ACEConfigFileFullPath" value="C:\somepath\Bin\ACEFile.xml" />

<add key="ILConfigFileFullPath" value="C:\somepath\Bin\IL.xml"/>

<add key="log4net.Config" value="log4net.config"/>
<add key="log4net.Config.Watch" value="True"/>

</appSettings>


<connectionStrings/>
<system.web>
<!-- 
        Visual Basic options:
        Set strict="true" to disallow all data type conversions 
        where data loss can occur. 
        Set explicit="true" to force declaration of all variables.
    -->


<compilation debug="true" strict="false" explicit="true" targetFramework="4.0"/>
<!--
  The <authentication> section enables configuration 
  of the security authentication mode used by 
  ASP.NET to identify an incoming user. 
-->
<authentication mode="Windows"/>
<!--
   The <customErrors> section enables configuration 
   of what to do if/when an unhandled error occurs 
   during the execution of a request. Specifically, 
   it enables developers to configure html error pages 
   to be displayed in place of a error stack trace.

   <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
     <error statusCode="403" redirect="NoAccess.htm" />
     <error statusCode="404" redirect="FileNotFound.htm" />
   </customErrors>
-->
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
  <namespaces>
    <clear/>
    <add namespace="System"/>
    <add namespace="System.Collections"/>
    <add namespace="System.Collections.Generic"/>
    <add namespace="System.Collections.Specialized"/>
    <add namespace="System.Configuration"/>
    <add namespace="System.Text"/>
    <add namespace="System.Text.RegularExpressions"/>
    <add namespace="System.Linq"/>
    <add namespace="System.Xml.Linq"/>
    <add namespace="System.Web"/>
    <add namespace="System.Web.Caching"/>
    <add namespace="System.Web.SessionState"/>
    <add namespace="System.Web.Security"/>
    <add namespace="System.Web.Profile"/>
    <add namespace="System.Web.UI"/>
    <add namespace="System.Web.UI.WebControls"/>
    <add namespace="System.Web.UI.WebControls.WebParts"/>
    <add namespace="System.Web.UI.HtmlControls"/>
  </namespaces>
</pages>
    <identity impersonate="true" />
</system.web>

</configuration>

log4net.config:                           &LT; / configSections&GT; - &GT;是的它仍然适用于我的评论。                                                                      

<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
  <param name="ApplicationName" value="Lending Service" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message %newline %exception"  />
  </layout>
  <filter type="log4net.Filter.LevelRangeFilter">
    <levelMin value="INFO"/>
    <levelMax value="FATAL"/>
  </filter> 
</appender>

<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
  <threshold value="FATAL"/> 
  <file value="webLog.log"/>
  <appendToFile value="true"/>
  <rollingStyle value="Size"/>
  <maxSizeRollBackups value="5"/>
  <maximumFileSize value="10MB"/>
  <staticLogFileName value="true"/>

  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %level %logger - %message%newline%exception"/>
  </layout>

</appender>


<root>
</root>

<logger name="LendingService.Global_asax">
  <appender-ref ref="RollingFileAppender"/>
  <appender-ref ref="EventLogAppender" />
</logger>

<logger name="LendingService.LendingService">
  <appender-ref ref="RollingFileAppender"/>
  <appender-ref ref="EventLogAppender" />    
</logger>  

 </log4net>
 <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
 </startup>
</configuration>

AssemblyInfo.vb中:

Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices

<Assembly: log4net.Config.XmlConfigurator(ConfigFile:="log4net.config",  Watch:=True)> 

的Global.asax:

Imports System.Web.SessionState
Imports IntelliLenderBUClasses


Public Class Global_asax
Inherits System.Web.HttpApplication
'Public objApplicant As New IntelliLenderBUClasses.ApplicantBU
Private Shared ReadOnly log As log4net.ILog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    ' Fires when the application is started


    'ACE
    Dim sACEPath As String
    sACEPath = System.Configuration.ConfigurationManager.AppSettings("ACEConfigFileFullPath")
    AceClientNet.BaseConfig.InitializeBU(sACEPath)
    'IL
    Dim sILPath As String
    sILPath = System.Configuration.ConfigurationManager.AppSettings("ILConfigFileFullPath")


    IntelliLenderBUClasses.BUBaseConfig.InitializeBU(sILPath)
    'LOGGING
    log4net.Config.XmlConfigurator.Configure() 'Error message happening here
    log.Info("LendingService Application Started")


End Sub

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
    ' Fires when the session is started
End Sub

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
    ' Fires at the beginning of each request
End Sub

Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)
    ' Fires upon attempting to authenticate the use
End Sub

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
    ' Fires when an error occurs
    Dim sendString As String = sender.ToString
    log.Error("LendingService Application Error: " & Server.GetLastError.Message)
End Sub

Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
    ' Fires when the session ends
End Sub

Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
    ' Fires when the application ends

    log.Info("LendingService Application Ending")
End Sub

End Class

1 个答案:

答案 0 :(得分:0)

您正在app.config文件中寻找配置。要更改此设置,您可以使用:

// Configure log4net using the .log4net file
[assembly: log4net.Config.XmlConfigurator(ConfigFileExtension="log4net",Watch=true)]
// This will cause log4net to look for a configuration file
// called TestApp.exe.log4net in the application base
// directory (i.e. the directory containing TestApp.exe)
// The config file will be watched for changes.

log4net.Config.XmlConfigurator(ConfigFileExtension="log4net",Watch=true)]

作为参考:

// Configure log4net using the .config file
[assembly: log4net.Config.XmlConfigurator(Watch=true)]
// This will cause log4net to look for a configuration file
// called TestApp.exe.config in the application base
// directory (i.e. the directory containing TestApp.exe)
// The config file will be watched for changes.
相关问题