Nlog: Local-ip Layout Renderer should not throw exceptions

Created on 10 Jun 2020  路  5Comments  路  Source: NLog/NLog

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: NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 4.7.2.11786. Product version: 4.7.2+024896f64b840a743d3fd89e29c2186681e7795f. GlobalAssemblyCache: False

Platform: .NET Core 3.1 on Linux (CentOS 7)

Current NLog config (xml or C#, if relevant)
I don't recall if I had "throwExceptions" enabled when I saw the error message. I think it was off.

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      throwExceptions="false" internalLogLevel="Info" internalLogToConsole="true" internalLogIncludeTimestamp="true" >
  <!-- used for file logging -->
  <variable name="logDir" value="/some/path/log" />
  <variable name="logFileBaseName" value="logFileName" />
  <!-- used for file logging -->
  <targets>
    <target type="File"
          name="file"
          encoding="UTF-8"
          layout="${date:universalTime=false:format=yyyy-MM-dd HH\:mm\:ss.ffffzzz} ${level:uppercase=true} ${processname:fullName=false} : ${assembly-version} (${hostname}:${local-ip}:${environm\ent-user}) Thread(${threadid}:${threadname}) ${callsite}:${callsite-linenumber} - ${message} ${exception:format=tostring}"
          lineEnding="Default"
          fileName="${logDir}/${logFileBaseName}.log"
          archiveFileName="${logDir}/Archive/${logFileBaseName}.{#}.log.zip"
          enableArchiveFileCompression="true"
          archiveOldFileOnStartup="false"
          maxArchiveFiles="60"
          archiveNumbering="Date"
          archiveEvery="Day"
          archiveDateFormat="yyyyMMdd"
          concurrentWrites="true"
  />
  </targets>
  <rules>
    <logger name="*" minlevel="Info" writeTo="file" />
  </rules>
</nlog>

I also have a similar target for elastic, but excluded it for brevity

  • What is the current result?
    The log message is not written out and instead an exception is thrown when rendering the ${local-ip} while on Linux with a "PlatformNotSupportedException"
2020-06-10 13:38:50.9425 Warn Failed to lookup NetworkInterface.GetAllNetworkInterfaces() Exception: System.PlatformNotSupportedException: The information requested is unavailable on the current platform.
   at System.Net.NetworkInformation.UnixUnicastIPAddressInformation.get_IsDnsEligible()
   at NLog.LayoutRenderers.LocalIpAddressLayoutRenderer.CalculateNetworkAddressScore(UnicastIPAddressInformation networkAddress, IPInterfaceProperties ipProperties)
   at NLog.LayoutRenderers.LocalIpAddressLayoutRenderer.LookupIpAddress()
2
  • What is the expected result?
    I would want the log message written to the target even if the layout is not supported, a "blank" string should be acceptable when a layout fails

  • Did you checked the Internal log?
    See above

  • Please post full exception details (message, stacktrace, inner exceptions)
    See above
  • Are there any workarounds? yes/no
    Yes, remove the ${local-ip} renderer from the log message
  • Is there a version in which it did work?
    ?
  • Can you help us by writing an unit test?
    maybe?
bug

Most helpful comment

Closing this issue as resolved by #4011

@johnjaylward You are very welcome to check if this pre-release build resolves the issue:

https://ci.appveyor.com/project/nlog/nlog/builds/33445802/artifacts (Download NLog.4.7.2.11884-PR4011.nupkg and use in local-path-nuget-repository)

All 5 comments

Hi! Thanks for opening your first issue here! Please make sure to follow the issue template - so we could help you better!

The warning you see is written to InternalLogger here:

https://github.com/NLog/NLog/blob/ec39759ea44d776f28cbf0de4a8f8f26fb33bbb3/src/NLog/LayoutRenderers/Machine/LocalIpAddressLayoutRenderer.cs#L115

But NLog should avoid using properties that will always fail on Linux. Created #4011 to fix this.

Btw. ${local-ip} can be very slow. It is recommended to use ${local-ip:cachedSeconds=60}

See also: https://github.com/NLog/NLog/wiki/Local-IP-Address-Layout-Renderer

Closing this issue as resolved by #4011

@johnjaylward You are very welcome to check if this pre-release build resolves the issue:

https://ci.appveyor.com/project/nlog/nlog/builds/33445802/artifacts (Download NLog.4.7.2.11884-PR4011.nupkg and use in local-path-nuget-repository)

Thanks for the quick fix!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Rapiiidooo picture Rapiiidooo  路  3Comments

BobSeu picture BobSeu  路  3Comments

MaximRouiller picture MaximRouiller  路  3Comments

smeegoan picture smeegoan  路  3Comments

Sam13 picture Sam13  路  3Comments