【发布时间】:2018-10-05 07:29:30
【问题描述】:
我有一个程序在这个星期一(2018-10-01)工作,但在星期三开始崩溃(星期二没有使用)。
该程序在客户处并处于发布形式,所以我无法调试它! 客户说“什么都没有改变”,我程序中的所有文件都和以前一样。
这是一个 C# Winforms 程序,我通过事件查看器发现崩溃发生在 NLog 启动时(在 ctor 中)。
我尝试使用内部日志记录,但没有创建日志文件。
关于问题是什么和/或我应该如何解决它的任何想法?
事件查看器应用程序中的消息:
DCMark Winform.exe 框架 版本:v4.0.30319 描述:进程因 未处理的异常。异常信息:System.Xml.XmlException 在 System.Xml.XmlTextReaderImpl.Throw(System.Exception) 在 System.Xml.XmlTextReaderImpl.Throw(System.String, System.String[])
在 System.Xml.XmlTextReaderImpl.ParseText(Int32 ByRef,Int32 ByRef, Int32 ByRef) 在 System.Xml.XmlTextReaderImpl.ParseText() 在 System.Xml.XmlTextReaderImpl.ParseElementContent() 在 System.Xml.XmlTextReaderImpl.Read() 在 System.Xml.XmlTextReader.Read() 在 System.Xml.XmlTextReaderImpl.Skip() 在 System.Xml.XmlTextReader.Skip() 在 System.Configuration.XmlUtil.StrictSkipToNextElement(System.Configuration.ExceptionAction) 在 System.Configuration.BaseConfigurationRecord.ScanSectionsRecursive(System.Configuration.XmlUtil, System.String,布尔,System.String, System.Configuration.OverrideModeSetting,布尔值)在 System.Configuration.BaseConfigurationRecord.ScanSectionsRecursive(System.Configuration.XmlUtil, System.String,布尔,System.String, System.Configuration.OverrideModeSetting,布尔值)在 System.Configuration.BaseConfigurationRecord.ScanSections(System.Configuration.XmlUtil) 在 System.Configuration.BaseConfigurationRecord.InitConfigFromFile()异常信息:System.Configuration.ConfigurationErrorsException
在 System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(布尔值) 在 System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(System.Configuration.ConfigurationSchemaErrors) 在 System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
在 System.Configuration.ClientConfigurationSystem.OnConfigRemoved(System.Object, System.Configuration.Internal.InternalConfigEventArgs)异常信息:System.Configuration.ConfigurationErrorsException
在 System.Configuration.ConfigurationManager.PrepareConfigSystem()
在 System.Configuration.ConfigurationManager.GetSection(System.String) 在 System.Configuration.ConfigurationManager.get_AppSettings() 在 NLog.Common.InternalLogger.GetSettingString(System.String, System.String) 在 NLog.Common.InternalLogger.GetSetting[[System.Boolean, mscorlib, 版本=4.0.0.0,文化=中性, PublicKeyToken=b77a5c561934e089]](System.String, System.String, Boolean) 在 NLog.Common.InternalLogger..cctor()异常信息:System.TypeInitializationException 在 DC.DCMark.Program.Main() 中的 DC.DCMark.Form1..ctor()
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>
【问题讨论】:
-
请注意,
throwExceptions="true"绝不应该在生产环境中使用。它仅用于单元测试或类似的。它有许多不需要的副作用。 -
很高兴知道!我只是在测试时添加它以查看是否会触发内部日志记录,但不会...
-
前。当 app.config 不可读时,它会导致 NLog 使您的应用程序崩溃。