Uploaded image for project: 'Log4net'
  1. Log4net
  2. LOG4NET-604

UdpAppender does not resolve environment variables .Net Core



    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.0.8
    • Fix Version/s: None
    • Component/s: Appenders
    • Labels:
    • Environment:
      Asp.Net Core 2.1. Windows 7, MacOs 10.12.6


      I have a UdpAppender defined in a .Net Framework 4.5.2 and a .Net Standard (Asp.Net Core 2.1) project.


      <appender name="UdpAppender" type="log4net.Appender.UdpAppender">
        <remoteAddress value="${LOGSERVER_HOST}" />
        <remotePort value="${LOGSERVER_PORT}" />
        <layout type="log4net.Layout.PatternLayout, log4net">
        <conversionPattern value="%d{yyyy-MM-dd'T'HH:mm:ss.fff'Z'} %-5p [%property\{server_name} %property\{service_name} %property\{service_port} %property\{CorrelationId}][%t] %c{5}:%L - %m%n"/>

      On .Net 4.5.2 the environment variable LOGSERVER_HOST and LOGSERVER_PORT are read and used by the appender.

      In .Net Standard I get the following error:

      log4net: Loading Appender [UdpAppender] type: [log4net.Appender.UdpAppender]
      log4net:ERROR Could not create Appender [UdpAppender] of type [log4net.Appender.UdpAppender]. Reported error follows.
      log4net.Util.TypeConverters.ConversionNotSupportedException: Cannot convert from type [System.String] value [${LOGSERVER_HOST}] to type
      [System.Net.IPAddress] ---> System.Net.Sockets.SocketException: No such host is known
      at System.Net.Dns.InternalGetHostByName(String hostName)
      at System.Net.Dns.ResolveCallback(Object context)
      — End of stack trace from previous location where exception was thrown —
      at System.Net.Dns.HostResolutionEndHelper(IAsyncResult asyncResult)
      at System.Net.Dns.EndGetHostEntry(IAsyncResult asyncResult)
      at System.Net.Dns.<>c.<GetHostEntryAsync>b__27_1(IAsyncResult asyncResult)
      at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Bool
      ean requiresSynchronization)
      — End of stack trace from previous location where exception was thrown —
      at log4net.Util.TypeConverters.IPAddressConverter.ConvertFrom(Object source)
      — End of inner exception stack trace —
      at log4net.Util.TypeConverters.IPAddressConverter.ConvertFrom(Object source)
      at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.SetParameter(XmlElement element, Object target)
      at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
      log4net:ERROR Appender named [UdpAppender] not found.


      I have run the project on Windows 7 and MacOs 10.12.6.  The only way to get the UdpAppender to work on .Net Core is to hard-code the address and port in the xml configuration.





            • Assignee:
              secovel Sean E. Covel
            • Votes:
              1 Vote for this issue
              3 Start watching this issue


              • Created: