Reputation: 361
We use a static logger class which internally utilizes Log4Net to create our log file. When we run the application in debug mode everything works fine and we get correct logs. However running the application in release mode yields incorrect log entries with missing class names, method names and line numbers.
I suspect that some debug information is missing in the build, but I could not find a solution yet onto how to provide this information to Log4Net without actually compiling in debug mode.
I tried to find this problem online, but I could not find any thread where somebody had the same problem (or I searched for it wrong).
The static class we use for logging looks like this:
using System;
using log4net.Core;
namespace Diagnostics
{
public static class MessageHandling
{
private static readonly LoggerFacade Logger = LoggerFacade.GetLoggerWrapper();
public static void SendDebug(string message)
{
Send(message, Level.Debug);
}
}
and the LoggerFacade
looks like this:
public class LoggerFacade
{
private static LoggerFacade _loggerFacade;
private static readonly ILogger Logger = LogManager.GetLogger(typeof(LoggerFacade)).Logger;
public static LoggerFacade GetLoggerWrapper()
{
if (_loggerFacade != null) return _loggerFacade;
_loggerFacade = new LoggerFacade();
GlobalContext.Properties["pid"] = Process.GetCurrentProcess().Id;
return _loggerFacade;
}
public void Log(string message, Level level, Type declaringType = null, Exception exception = null)
{
Logger.Log(declaringType ?? typeof(LoggerFacade), level, message, exception);
}
}
The log messages should (and do in debug mode) look like this:
2019-08-23 11:09:15,019 INFO [1] [MyClass] (MyMethod) 'Line: 1' -> Message
But in release mode they look like this:
2019-08-23 11:09:15,019 INFO [1] [?] (?) 'Line: ?' -> Message
Edit: The PDB files are included in the release build and the release is build using code optimizations (visual studio checkmark). Could these code optimizations be the problem?
Upvotes: 0
Views: 829