Vb.net 如何修复基于Nlog假设错误路径的TypeInitializationException

Vb.net 如何修复基于Nlog假设错误路径的TypeInitializationException,vb.net,visual-studio-2013,nlog,Vb.net,Visual Studio 2013,Nlog,我正在Visual Studio Express 2013的控制台应用程序中使用nLog 4.0.1。 在VS中运行应用程序本身可以工作;它在编译相对目录中的.exe后也可以工作,如bin\Debug或bin\Release。 但是,如果我将它编译成另一个目录(\\192.168.3.55\vol3\programs\test),它将不起作用 这是我的app.config: <?xml version="1.0" encoding="utf-8"?> <configuratio

我正在Visual Studio Express 2013的控制台应用程序中使用nLog 4.0.1。
在VS中运行应用程序本身可以工作;它在编译相对目录中的.exe后也可以工作,如
bin\Debug
bin\Release

但是,如果我将它编译成另一个目录(
\\192.168.3.55\vol3\programs\test
),它将不起作用

这是我的app.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <!-- ... -->
    </assemblyBinding>
  </runtime>
  <connectionStrings>
    <!-- ... -->
  </connectionStrings>
  <appSettings>
    <!-- ... -->
  </appSettings>
  <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd" autoReload="true" throwExceptions="false" internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
    <variable name="startDatetime" value="${date:format=yyMMdd}" />
    <targets>
      <target name="logfile" xsi:type="File" fileName="\\192.168.3.71\log\test_${startDatetime}.dbg" layout="[${date:format=yyyyMMddHHmmssfff}][${level}] ${message}" />layout="${date:format=yyyyMMddHHmmss} ${message}" />-->
      <target xsi:type="ColoredConsole" name="console" encoding="utf-8" layout="${message}">
      </target>
    </targets>
    <rules>
      <logger name="*" minlevel="Debug" writeTo="logfile" />
      <logger name="*" minlevel="Debug" writeTo="console" />
    </rules>
  </nlog>
</configuration>
这是my.vbproj的一部分:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <DefineDebug>false</DefineDebug>
    <DefineTrace>true</DefineTrace>
    <Optimize>true</Optimize>
    <OutputPath>\\192.168.3.55\vol3\programs\test\</OutputPath>
    <DocumentationFile>test.xml</DocumentationFile>
    <NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
    <Prefer32Bit>false</Prefer32Bit>
  </PropertyGroup>
意味着,找不到路径的一部分,
\\192.168.3.55\vol3\vol3\programs\test
,该路径实际上不存在。但我不知道这是怎么发生的,“vol3”被拍了两次。我在我的设置中使用了
\\192.168.3.55\vol3\programs\test\
,但在这个目录中释放后,nLog将路径转换为
\\192.168.3.55\vol3\vol3\programs\test
,并失败。

如何告诉nLog使用正确的路径?

我们遇到了相同的问题。将NLog从4.0.1降级到3.2.1就成功了。

这是一个(而不是4.0.0)。这将在4.1.0中解决。

是的,我必须承认我在问题中陈述了错误的NLog版本。问题发生在版本4.0.1中,我的程序在降级到4.0.0后工作。谢谢你的链接。
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <DefineDebug>false</DefineDebug>
    <DefineTrace>true</DefineTrace>
    <Optimize>true</Optimize>
    <OutputPath>\\192.168.3.55\vol3\programs\test\</OutputPath>
    <DocumentationFile>test.xml</DocumentationFile>
    <NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
    <Prefer32Bit>false</Prefer32Bit>
  </PropertyGroup>
Unbehandelte Ausnahme: System.TypeInitializationException: Der Typeninitialisierer für "test.Test" hat eine Ausnahme verursacht. ---> System.Configuration.ConfigurationErrorsException: Beim Erstellen des Konfigurationsabschnittshandlers für "nlog" ist ein Fehler aufgetreten.: Der Typeninitialisierer für "NLog.Config.Configuration
ItemFactory" hat eine Ausnahme verursacht. (\\192.168.3.55\vol3\programs\test\test.exe.Config line 36) ---> System.TypeInitializationException: Der Typeninitialisierer für "NLog.Config.ConfigurationItemFactory" hat eine Ausnahme verursacht. ---> System.IO.DirectoryNotFoundException: Ein Teil des Pfades "\\192.168.3.55\vol3\vol3\programs\test" konnte nicht gefunden werden.
   bei System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   bei System.IO.FileSystemEnumerableIterator`1.CommonInit()
   bei System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
   bei System.IO.Directory.InternalGetFileDirectoryNames(String path, String userPathOriginal, String searchPattern, Boolean includeFiles, Boolean includeDirs, SearchOption searchOption, Boolean checkHost)
   bei System.IO.Directory.InternalGetFiles(String path, String searchPattern, SearchOption searchOption)
   bei NLog.Config.ConfigurationItemFactory.BuildDefaultFactory()
   bei NLog.Config.ConfigurationItemFactory..cctor()
   --- Ende der internen Ausnahmestapelüberwachung ---
   bei NLog.Config.ConfigurationItemFactory.get_Default()
   bei NLog.Config.XmlLoggingConfiguration..ctor(XmlElement element, String fileName)
   bei NLog.Config.ConfigSectionHandler.Create(XmlNode section, IAppDomain appDomain)
   bei System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionImpl(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXml
Reader reader)
   bei System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object pa
rentConfig, ConfigXmlReader reader)
   bei System.Configuration.RuntimeConfigurationRecord.CreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)
   bei System.Configuration.BaseConfigurationRecord.CallCreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader, String filename, Int32 line)
   --- Ende der internen Ausnahmestapelüberwachung ---
   bei System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTruste
d, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
   bei System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionReco
rd, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
   bei System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
   bei System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
   bei System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
   bei System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
   bei System.Configuration.ConfigurationManager.GetSection(String sectionName)
   bei NLog.LogFactory.get_Configuration()
   bei NLog.LogFactory.GetLogger(LoggerCacheKey cacheKey)
   bei NLog.LogManager.GetCurrentClassLogger()