NLog: NLog failed to parse config file - Target Console not found.

Hi! Thanks for reporting this feature/bug/question!

Please keep / fill in the relevant info from this template so that we can help you as best as possible.

QUESTIONS are preferred on StackOverflow. You could expect a faster response there (but do include all the info below). Use the tag “nlog” https://stackoverflow.com/questions/ask

For .NET Core users, please check the platform support: https://github.com/NLog/NLog/wiki/platform-support

NLog version: (e.g. 4.4.13) 4.5.11

Platform: .NET Core 2

Current NLog config (xml or C#, if relevant)

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      autoReload="true"
      internalLogLevel="info"
      internalLogFile="internal-nlog.txt">

  <!-- enable asp.net core layout renderers -->
  <extensions>
    <add assembly="NLog.Web.AspNetCore"/>
  </extensions>

  <!-- the targets to write to -->
  <targets>

      <target xsi:type="Console"
          name="String"
          detectConsoleAvailable="false"
          layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}"/>
  </targets>

  <!-- rules to map from logger name to target -->
  <rules>
    <!--All logs, including from Microsoft-->
    <logger name="*" minlevel="Trace" writeTo="Console" />

    <!--Skip non-critical Microsoft logs and so log only own logs-->
    <logger name="Microsoft.*" maxLevel="Info" final="true" /> <!-- BlackHole without writeTo -->
    <logger name="*" minlevel="Trace" writeTo="Console" />
  </rules>
</nlog>

  • What is the current result? App start, but no logs are written
  • What is the expected result? Logs are written to console
  • Did you checked the Internal log?
2018-12-06 16:02:45.4642 Info Message Template Auto Format enabled
2018-12-06 16:02:45.4816 Info Loading assembly: NLog.Web.AspNetCore
2018-12-06 16:02:45.5330 Info Adding target Console Target[String]
2018-12-06 16:02:45.5639 Error Parsing configuration from <>/nlog.config failed. Exception: NLog.NLogConfigurationException: Exception when parsing <>/nlog.config.  ---> NLog.NLogConfigurationException: Target Console not found.
   at NLog.Config.XmlLoggingConfiguration.ParseLoggerElement(NLogXmlElement loggerElement, IList`1 rulesCollection)
   at NLog.Config.XmlLoggingConfiguration.ParseRulesElement(NLogXmlElement rulesElement, IList`1 rulesCollection)
   at NLog.Config.XmlLoggingConfiguration.ParseNLogElement(NLogXmlElement nlogElement, String filePath, Boolean autoReloadDefault)
   at NLog.Config.XmlLoggingConfiguration.Initialize(XmlReader reader, String fileName, Boolean ignoreErrors)
   --- End of inner exception stack trace ---
2018-12-06 16:02:45.5652 Warn Failed loading config from <>/nlog.config. Invalid XML?
2018-12-06 16:02:45.5734 Info Found 15 configuration items
  • Please post full exception details (message, stacktrace, inner exceptions)
  • Are there any workarounds? no
  • Is there a version in which it did work?
  • Can you help us by writing an unit test? yes

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 19 (13 by maintainers)

Most upvoted comments

#3039 has been merged, so assume this is fixed. Will reopen if not!

Created #3039 for NLog 4.6 that should fix the problem with Xamarin Linker removing everything from NLog.dll Allowing NLog.config-files to work without needing to specify --linkskip=NLog