与vb.net集成时出现log4net错误

时间:2013-10-15 18:02:53

标签: vb.net log4net

当我将log4net部分添加到app.config文件时,出现以下错误:

{“创建表单时出错。有关详细信息,请参阅Exception.InnerException。错误是:由于db错误导致无法启动GlobalChangeReason加载:'prjProcessWorkSheets.AicDatabase'的类型初始化程序引发异常。”}

我要添加的log4net部分是:

  <log4net>
    <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
      <filter type="log4net.Filter.LevelRangeFilter">
        <levelMin value="INFO" />
      </filter>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
      </layout>
    </appender>


    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
      <file value="C:\Test\Test.log" />
      <appendToFile value="true" />
      <rollingStyle value="Composite" />
      <datePattern value="yyyyMMdd" />
      <maxSizeRollBackups value="10" />
      <maximumFileSize value="10MB" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline%exception%newline" />
      </layout>
    </appender>

    <root>
      <level value="DEBUG" />
      <appender-ref ref="ConsoleAppender" />
      <appender-ref ref="RollingLogFileAppender" />
    </root>

    <logger name="ProcessingApp">
      <level value="INFO" />
      <appender-ref ref="SmtpAppender"/>
      <appender-ref ref="RollingLogFileAppender" />
    </logger>

  </log4net>

已添加到AssemblyInfo.vb

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

错误堆栈跟踪:

prdProcessWorkSheets.My.MyProject.MyForms.Create_ Instance _ [T](T Instance)in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 190    在prjProcessWorkSheets.My.MyProject.MyForms.get_frmSteps()    at prjProcessWorkSheets.My.MyApplication.OnCreateMainForm()in C:\ Users \ mattoou \ Desktop \ VSS-REPO \ Processing Application \ prjProcessWorkSheets \ My Project \ Application.Designer.vb:第35行    在Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()    在Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()    在Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String [] commandLine)    at prjProcessWorkSheets.My.MyApplication.Main(String [] Args)in 17d14f5c-a337-4978-8281-53493378c1071.vb:第81行    在System.AppDomain._nExecuteAssembly(RuntimeAssembly程序集,String [] args)    在System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args)    在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()    在System.Threading.ThreadHelper.ThreadStart_Context(对象状态)    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean ignoreSyncCtx)    在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)    在System.Threading.ThreadHelper.ThreadStart()

1 个答案:

答案 0 :(得分:0)

您如何在代码中使用 Log4Net?这部分错误说明了这一点:

  

'prjProcessWorkSheets.AicDatabase'的类型初始化程序引发了异常。

prjProcessWorkSheets.AicDatabase似乎在初始化时尝试做某事。一个静态构造函数?内联初始化成员?如果模式与log4net配置有关,那么我猜测一个它正在尝试做的事情就是初始化一个记录器。

是你正在寻找的例外。它是你收到的那个的内在例外吗?如果没有,请在调试器中停止它,或者在可以捕获异常的方法中初始化类。它应该告诉你log4net有什么问题。