title: NLog Exception when parsing nlog.config - Target cannot be found: 'EventLog'
body: <p>I'm developing a <em>C# .NET Core 2.2 Web-Api</em> on <em>Visual Studio 2017</em>.
  I implement <strong>NLog</strong> 4.6.1 like described on <a href="https://github.com/NLog/NLog.Web/wiki/Getting-started-with-ASP.NET-Core-2" rel="nofollow noreferrer">github</a>.
  When I start my application using IIS <strong>NLog does not write into the Elasticsearch</strong>. A <strong>error occurs at the line</strong> at program.cs</p>
  
  <pre><code>var logger = NLog.Web.NLogBuilder.ConfigureNLog("NLog.config").GetCurrentClassLogger();
  </code></pre>
  
  <p>I find a error message at <em>NLogError.log</em>:</p>
  
  <pre><code>2019-06-12 09:00:49.1606 Error Penter code herearsing configuration from NLog.config failed. Exception: NLog.NLogConfigurationException: Exception when parsing NLog.config.  ---&gt; System.ArgumentException: Target cannot be found: 'EventLog'
     at NLog.Config.Factory`2.CreateInstance(String itemName)
     at NLog.Config.LoggingConfigurationParser.ParseTargetsElement(ILoggingConfigurationElement targetsElement)
     at NLog.Config.LoggingConfigurationParser.ParseNLogSection(ILoggingConfigurationElement configSection)
     at NLog.Config.LoggingConfigurationParser.LoadConfig(ILoggingConfigurationElement nlogConfig, String basePath)
     at NLog.Config.XmlLoggingConfiguration.ParseNLogElement(ILoggingConfigurationElement nlogElement, String filePath, Boolean autoReloadDefault)
     at NLog.Config.XmlLoggingConfiguration.Initialize(XmlReader reader, String fileName, Boolean ignoreErrors)
     --- End of inner exception stack trace ---
  </code></pre>
  
  <p>I tried to shorten my config file to avoid other problems but still same error. The target "EventLog" is to find there.</p>
  
  <p>NLog.config:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
        &lt;nlog autoReload="true" throwExceptions="false"
            internalLogLevel="Error" internalLogFile="NLogError.log"
            xmlns="http://www.nlog-project.org/schemas/NLog.xsd" 
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
            &lt;targets&gt;
              &lt;target name="EventLog" xsi:type="EventLog"
                layout="${longdate} ${level} ${callsite} -&gt; ${message} 
                ${exception:format=Message,StackTrace}"
                source="MonDBSvc" /&gt;
            &lt;/targets&gt;
            &lt;rules&gt;
              &lt;logger name="MonDbSvc" minlevel="Error" writeTo="EventLog" 
                log="Application" /&gt;
            &lt;/rules&gt;
        &lt;/nlog&gt;
  </code></pre>
  
  <p>The NLog.config file and the program.cs file are on the same root level at the application folder.</p>
  
  <p>I tried writing <strong><em>NL</strong>og.config</em> nad <strong><em>nl</strong>og.config</em> for the filename and at this code line above.</p>
  
  <p><strong>What could cause this parsing problem? What could I try to fix it?</strong></p>
  
  <p>Thanks for support!</p>
  
  <p>When I change the log level from error to warn I get a more explicit message. I'm quit shure that the xml is valid as a xml. </p>
  
  <pre><code>2019-06-12 10:27:51.3735 Info Message Template Auto Format enabled
  2019-06-12 10:27:51.4347 Error Parsing configuration from NLog.config failed. Exception: NLog.NLogConfigurationException: Exception when parsing NLog.config.  ---&gt; System.ArgumentException: Target cannot be found: 'EventLog'
     at NLog.Config.Factory`2.CreateInstance(String itemName)
     at NLog.Config.LoggingConfigurationParser.ParseTargetsElement(ILoggingConfigurationElement targetsElement)
     at NLog.Config.LoggingConfigurationParser.ParseNLogSection(ILoggingConfigurationElement configSection)
     at NLog.Config.LoggingConfigurationParser.LoadConfig(ILoggingConfigurationElement nlogConfig, String basePath)
     at NLog.Config.XmlLoggingConfiguration.ParseNLogElement(ILoggingConfigurationElement nlogElement, String filePath, Boolean autoReloadDefault)
     at NLog.Config.XmlLoggingConfiguration.Initialize(XmlReader reader, String fileName, Boolean ignoreErrors)
     --- End of inner exception stack trace ---
  2019-06-12 10:27:51.4347 Warn Failed loading config from NLog.config. Invalid XML?
  2019-06-12 10:27:51.4597 Debug Watching path 'C:\Repositories\DataPicker\DataPicker\DataPicker.Api' filter 'NLog.config' for changes.
  2019-06-12 10:27:51.4597 Debug --- NLog configuration dump ---
  2019-06-12 10:27:51.4680 Debug Targets:
  2019-06-12 10:27:51.4680 Debug Rules:
  2019-06-12 10:27:51.4680 Debug --- End of NLog configuration dump ---
  2019-06-12 10:27:51.4680 Trace FindReachableObject&lt;System.Object&gt;:
  2019-06-12 10:27:51.4680 Info Found 0 configuration items
  2019-06-12 10:27:51.4889 Debug Targets not configured for logger: DataPicker.Api.Program
  2019-06-12 10:27:55.2679 Debug ScanAssembly('NLog.Web.AspNetCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c')
  2019-06-12 10:27:55.7717 Debug Hide assemblies for callsite
  2019-06-12 10:27:55.7717 Trace Assembly 'NLog.Extensions.Logging, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c' will be hidden in callsite stacktrace
  2019-06-12 10:27:55.7855 Debug ScanAssembly('NLog.Extensions.Logging, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c')
  2019-06-12 10:27:55.7855 Trace Assembly 'Microsoft.Extensions.Logging, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' will be hidden in callsite stacktrace
  2019-06-12 10:27:55.7855 Trace Assembly 'Microsoft.Extensions.Logging.Abstractions, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' will be hidden in callsite stacktrace
  2019-06-12 10:27:55.8068 Debug Targets not configured for logger: Microsoft.AspNetCore.Hosting.Internal.ApplicationLifetime
  2019-06-12 10:27:55.8068 Debug Targets not configured for logger: Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv
  2019-06-12 10:27:55.8178 Debug Targets not configured for logger: Microsoft.AspNetCore.Server.Kestrel
  2019-06-12 10:27:55.8465 Debug Targets not configured for logger: Microsoft.AspNetCore.DataProtection.TypeForwardingActivator
  2019-06-12 10:27:55.8465 Debug Targets not configured for logger: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager
  2019-06-12 10:27:55.8622 Debug Targets not configured for logger: Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.CngGcmAuthenticatedEncryptorFactory
  2019-06-12 10:27:55.8622 Debug Targets not configured for logger: Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.CngCbcAuthenticatedEncryptorFactory
  2019-06-12 10:27:55.8622 Debug Targets not configured for logger: Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ManagedAuthenticatedEncryptorFactory
  2019-06-12 10:27:55.8776 Debug Targets not configured for logger: Microsoft.AspNetCore.DataProtection.XmlEncryption.DpapiXmlEncryptor
  2019-06-12 10:27:55.8776 Debug Targets not configured for logger: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository
  2019-06-12 10:27:55.9084 Debug Targets not configured for logger: Microsoft.AspNetCore.DataProtection.KeyManagement.DefaultKeyResolver
  2019-06-12 10:27:55.9084 Debug Targets not configured for logger: Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider
  2019-06-12 10:27:55.9084 Debug Targets not configured for logger: Microsoft.AspNetCore.DataProtection.Internal.DataProtectionStartupFilter
  2019-06-12 10:27:55.9835 Debug Targets not configured for logger: Microsoft.AspNetCore.DataProtection.XmlEncryption.DpapiXmlDecryptor
  2019-06-12 10:27:56.1465 Debug Targets not configured for logger: Microsoft.AspNetCore.Mvc.Formatters.JsonPatchInputFormatter
  2019-06-12 10:27:56.1465 Debug Targets not configured for logger: Microsoft.AspNetCore.Mvc.Formatters.JsonInputFormatter
  2019-06-12 10:27:56.1674 Debug Targets not configured for logger: Microsoft.AspNetCore.Mvc.RazorPages.Internal.RazorProjectPageRouteModelProvider
  2019-06-12 10:27:56.2420 Debug Targets not configured for logger: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker
  2019-06-12 10:27:56.2524 Debug Targets not configured for logger: Microsoft.AspNetCore.Mvc.Razor.Internal.RazorViewCompiler
  2019-06-12 10:27:56.2524 Debug Targets not configured for logger: Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector
  2019-06-12 10:27:56.2707 Debug Targets not configured for logger: Microsoft.AspNetCore.Mvc.ViewFeatures.CookieTempDataProvider
  2019-06-12 10:27:56.2707 Debug Targets not configured for logger: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker
  2019-06-12 10:27:56.2814 Debug Targets not configured for logger: Microsoft.AspNetCore.Mvc.Internal.ActionSelector
  2019-06-12 10:27:56.2814 Debug Targets not configured for logger: Microsoft.AspNetCore.Mvc.Internal.MvcRouteHandler
  2019-06-12 10:27:56.2984 Debug Targets not configured for logger: Microsoft.AspNetCore.Builder.RouterMiddleware
  2019-06-12 10:27:56.3256 Debug Targets not configured for logger: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware
  2019-06-12 10:27:56.3523 Debug Targets not configured for logger: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware
  2019-06-12 10:27:56.3523 Debug Targets not configured for logger: Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware
  2019-06-12 10:27:56.3592 Debug Targets not configured for logger: Microsoft.AspNetCore.HttpOverrides.ForwardedHeadersMiddleware
  2019-06-12 10:27:56.3592 Debug Targets not configured for logger: Microsoft.AspNetCore.Hosting.Internal.WebHost
  2019-06-12 10:27:56.3783 Debug Targets not configured for logger: Microsoft.AspNetCore.Hosting.Internal.HostedServiceExecutor
  </code></pre>