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