0

当我将 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)> 

错误堆栈跟踪:

prjProcessWorkSheets.My.MyProject.MyForms.Create_Instance __[T](T Instance) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 190 at 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:line 35 at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine) at prjProcessWorkSheets.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81 at System.AppDomain._nExecuteAssembly System.AppDomain.ExecuteAssembly (String assemblyFile,Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在 System.Threading.ThreadHelper.ThreadStart_Context(Object state) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback 回调, 对象状态的证据 assemblySecurity, String[] args), Boolean ignoreSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 在 System.Threading.ThreadHelper.ThreadStart()ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()

4

1 回答 1

0

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

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

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

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

于 2013-10-15T18:12:02.203 回答