NLog 4.1.2 在构造函数中崩溃
NLog 4.1.2 crashes in constructor
我有一个程序在这个星期一 (2018-10-01) 工作,但在星期三开始崩溃(它在星期二没有使用)。
程序在客户处,处于发布状态,无法调试!
客户说"Nothing has changed",我程序里的所有文件都和以前一样
这是一个 C# Winforms 程序,我通过事件查看器发现崩溃发生在 NLog 启动时(在 ctor 中)。
我尝试使用内部日志记录,但没有创建日志文件。
关于问题是什么的任何想法and/or我应该如何解决它?
事件查看器应用程序中的消息:
DCMark Winform.exe Framework
Version: v4.0.30319 Description: The process was terminated due to an
unhandled exception. Exception Info: System.Xml.XmlException at
System.Xml.XmlTextReaderImpl.Throw(System.Exception) at
System.Xml.XmlTextReaderImpl.Throw(System.String, System.String[])
at System.Xml.XmlTextReaderImpl.ParseText(Int32 ByRef, Int32 ByRef,
Int32 ByRef) at System.Xml.XmlTextReaderImpl.ParseText() at
System.Xml.XmlTextReaderImpl.ParseElementContent() at
System.Xml.XmlTextReaderImpl.Read() at
System.Xml.XmlTextReader.Read() at
System.Xml.XmlTextReaderImpl.Skip() at
System.Xml.XmlTextReader.Skip() at
System.Configuration.XmlUtil.StrictSkipToNextElement(System.Configuration.ExceptionAction)
at
System.Configuration.BaseConfigurationRecord.ScanSectionsRecursive(System.Configuration.XmlUtil,
System.String, Boolean, System.String,
System.Configuration.OverrideModeSetting, Boolean) at
System.Configuration.BaseConfigurationRecord.ScanSectionsRecursive(System.Configuration.XmlUtil,
System.String, Boolean, System.String,
System.Configuration.OverrideModeSetting, Boolean) at
System.Configuration.BaseConfigurationRecord.ScanSections(System.Configuration.XmlUtil)
at System.Configuration.BaseConfigurationRecord.InitConfigFromFile()
Exception Info: System.Configuration.ConfigurationErrorsException
at
System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean)
at
System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(System.Configuration.ConfigurationSchemaErrors)
at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
at
System.Configuration.ClientConfigurationSystem.OnConfigRemoved(System.Object,
System.Configuration.Internal.InternalConfigEventArgs)
Exception Info: System.Configuration.ConfigurationErrorsException
at System.Configuration.ConfigurationManager.PrepareConfigSystem()
at System.Configuration.ConfigurationManager.GetSection(System.String)
at System.Configuration.ConfigurationManager.get_AppSettings() at
NLog.Common.InternalLogger.GetSettingString(System.String,
System.String) at
NLog.Common.InternalLogger.GetSetting[[System.Boolean, mscorlib,
Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089]](System.String, System.String,
Boolean) at NLog.Common.InternalLogger..cctor()
Exception Info: System.TypeInitializationException at
DC.DCMark.Form1..ctor() at DC.DCMark.Program.Main()
NLog.config 文件
<?xml version="1.0" encoding="utf-8" ?>
<nlog throwExceptions="true"
internalLogFile="C:/Temp/log.txt" internalLogLevel="Trace">
<targets>
<target xsi:type="File" name="f" fileName="${specialfolder:folder=CommonApplicationData}/Foo/Bar/Logs/Bar_${shortdate}.log"
layout="${longdate} | ${uppercase:${level}} | ${callsite} | ${message} | ${exception:format=ToString}" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="f" />
</rules>
</nlog>
编辑:添加了 App.config 文件
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="DC.DCMark.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<userSettings>
<DC.DCMark.Properties.Settings>
<setting name="Location" serializeAs="String">
<value>400, 100</value>
</setting>
<setting name="Size" serializeAs="String">
<value>840, 900</value>
</setting>
<setting name="Maximised" serializeAs="String">
<value>False</value>
</setting>
<setting name="Minimised" serializeAs="String">
<value>False</value>
</setting>
</DC.DCMark.Properties.Settings>
</userSettings>
</configuration>
您的网站出现 XML 错误。config/app.config
在 NLog 4.4 中,修复了 NLog 不会崩溃的问题。 (参见 bug report),所以更新会修复它。更新到最新版本,建议4.5.10。
我发现错误了!
我找到了这个
其中表示在 %localappdata%\companyname\programname...
中创建了 app.config 的副本
我删除了名称中包含该程序名称的所有目录。
一切正常!!
感谢所有帮助,没有它我就找不到解决方案!
我有一个程序在这个星期一 (2018-10-01) 工作,但在星期三开始崩溃(它在星期二没有使用)。
程序在客户处,处于发布状态,无法调试! 客户说"Nothing has changed",我程序里的所有文件都和以前一样
这是一个 C# Winforms 程序,我通过事件查看器发现崩溃发生在 NLog 启动时(在 ctor 中)。
我尝试使用内部日志记录,但没有创建日志文件。
关于问题是什么的任何想法and/or我应该如何解决它?
事件查看器应用程序中的消息:
DCMark Winform.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.Xml.XmlException at System.Xml.XmlTextReaderImpl.Throw(System.Exception) at System.Xml.XmlTextReaderImpl.Throw(System.String, System.String[])
at System.Xml.XmlTextReaderImpl.ParseText(Int32 ByRef, Int32 ByRef, Int32 ByRef) at System.Xml.XmlTextReaderImpl.ParseText() at System.Xml.XmlTextReaderImpl.ParseElementContent() at System.Xml.XmlTextReaderImpl.Read() at System.Xml.XmlTextReader.Read() at System.Xml.XmlTextReaderImpl.Skip() at System.Xml.XmlTextReader.Skip() at System.Configuration.XmlUtil.StrictSkipToNextElement(System.Configuration.ExceptionAction) at System.Configuration.BaseConfigurationRecord.ScanSectionsRecursive(System.Configuration.XmlUtil, System.String, Boolean, System.String, System.Configuration.OverrideModeSetting, Boolean) at System.Configuration.BaseConfigurationRecord.ScanSectionsRecursive(System.Configuration.XmlUtil, System.String, Boolean, System.String, System.Configuration.OverrideModeSetting, Boolean) at System.Configuration.BaseConfigurationRecord.ScanSections(System.Configuration.XmlUtil) at System.Configuration.BaseConfigurationRecord.InitConfigFromFile()Exception Info: System.Configuration.ConfigurationErrorsException
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean) at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(System.Configuration.ConfigurationSchemaErrors) at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
at System.Configuration.ClientConfigurationSystem.OnConfigRemoved(System.Object, System.Configuration.Internal.InternalConfigEventArgs)Exception Info: System.Configuration.ConfigurationErrorsException
at System.Configuration.ConfigurationManager.PrepareConfigSystem()
at System.Configuration.ConfigurationManager.GetSection(System.String) at System.Configuration.ConfigurationManager.get_AppSettings() at NLog.Common.InternalLogger.GetSettingString(System.String, System.String) at NLog.Common.InternalLogger.GetSetting[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.String, System.String, Boolean) at NLog.Common.InternalLogger..cctor()Exception Info: System.TypeInitializationException at DC.DCMark.Form1..ctor() at DC.DCMark.Program.Main()
NLog.config 文件
<?xml version="1.0" encoding="utf-8" ?>
<nlog throwExceptions="true"
internalLogFile="C:/Temp/log.txt" internalLogLevel="Trace">
<targets>
<target xsi:type="File" name="f" fileName="${specialfolder:folder=CommonApplicationData}/Foo/Bar/Logs/Bar_${shortdate}.log"
layout="${longdate} | ${uppercase:${level}} | ${callsite} | ${message} | ${exception:format=ToString}" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="f" />
</rules>
</nlog>
编辑:添加了 App.config 文件
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="DC.DCMark.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
<userSettings>
<DC.DCMark.Properties.Settings>
<setting name="Location" serializeAs="String">
<value>400, 100</value>
</setting>
<setting name="Size" serializeAs="String">
<value>840, 900</value>
</setting>
<setting name="Maximised" serializeAs="String">
<value>False</value>
</setting>
<setting name="Minimised" serializeAs="String">
<value>False</value>
</setting>
</DC.DCMark.Properties.Settings>
</userSettings>
</configuration>
您的网站出现 XML 错误。config/app.config
在 NLog 4.4 中,修复了 NLog 不会崩溃的问题。 (参见 bug report),所以更新会修复它。更新到最新版本,建议4.5.10。
我发现错误了!
我找到了这个 其中表示在 %localappdata%\companyname\programname...
中创建了 app.config 的副本我删除了名称中包含该程序名称的所有目录。
一切正常!!
感谢所有帮助,没有它我就找不到解决方案!