Reputation: 111
Running Ubuntu on a Minnow Max trying to use log4net in a mono application the Udp appender does not log to the remote location. Running the same application on a Raspberry Pi 2 with identical configs the Udp appender logs correctly. When I enable log4net logging there are no errors and the output of the log was identical on both machines. I have used nmap and Wire Shark to verify the Udp port is open and sending packets. The file appender on the Minnow is logging correctly.
C# Code
private static readonly ILog Logger = LogManager.GetLogger($"Drake.Mfg.DCS.{Environment.MachineName}");
public static LogLevel ConsoleLevel { get; set; }
public static void LogToNet(string message, LogLevel logLevel)
{
try
{
switch (logLevel)
{
case LogLevel.None:
break;
case LogLevel.Trace:
Logger.Trace(message);
break;
case LogLevel.Debug:
Logger.Debug(message);
break;
case LogLevel.Info:
Logger.Info(message);
break;
case LogLevel.Warn:
Logger.Warn(message);
break;
case LogLevel.Error:
Logger.Error(message);
break;
case LogLevel.Fatal:
Logger.Fatal(message);
break;
case LogLevel.AlwaysLog:
Logger.Info(message);
break;
default:
throw new ArgumentOutOfRangeException(nameof(consoleLevel), consoleLevel, null);
}
Console.WriteLine($"{message}");
Console.ResetColor();
}
Log4Net.Config
<?xml version="1.0" encoding="utf-8"?>
<log4net>
<appender name="Main" type="log4net.Appender.RollingFileAppender">
<file value="dcsLog.log" />
<appendToFile value="true" />
<maximumFileSize value="1GB" />
<maxSizeRollBackups value="3" />
<encoding value="utf-8" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%utcdate{ISO8601} %-8level %-28logger %message%newline" />
</layout>
</appender>
<appender name="UdpAppender" type="log4net.Appender.UdpAppender">
<remoteAddress value="192.168.10.53" />
<remotePort value="7071" />
<layout type="log4net.Layout.XmlLayoutSchemaLog4j" />
<encoding value="utf-8" />
</appender>
<root>
<level value="Debug" />
<appender-ref ref="Main" />
</root>
<logger name="Drake.Mfg.DCS.DEI80021">
<level value="Debug" />
<appender-ref ref="UdpAppender" />
</logger>
</log4net>
Mono
Mono JIT compiler version 4.3.0 (master/844fc33 Tue Oct 20 14:21:50 EDT 2015) Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com TLS: __thread SIGSEGV: altstack Notifications: epoll Architecture: amd64 Disabled: none Misc: softdebug LLVM: supported, not enabled. GC: sgen
log4net
1.2.15
Upvotes: 1
Views: 977
Reputation: 111
The Log4Net config is case sensitive as xml is. The Hostname for the Minnow was in lowercase and I was looking for upper. Because I do not have sole control over hostnames I used a To Upper.
ILog logger = LogManager.GetLogger($"Drake.Mfg.DCS.{Environment.MachineName.ToUpper()}");
Fixed it now and in the future.
Upvotes: 1