What is my purpose: log file output will contain the name of the class, method and the line that was wrote by the log (in the example below – Program, Main, 16)
The problem: the log file output is contain the name of the class, method and the line of the wrapper class and not the details of the "main" function.
I have 2 projects
Project 1 "Log4netCommon" - that include the log4net.dll and wrapper for the log functionally
Project 2 "NoDependenceLog4net"- that reference to "Log4netCommon" and contain the main function that
Part of My config file:
<appender name="File" type="log4net.Appender.FileAppender">
<file value="C:/Users/zxc/Desktop/MyFile.txt" />
<layout type="log4net.Layout.PatternLayout" >
<conversionPattern value="%date [%thread] %-5level %c - %m%n %logger [%-5method] %line - [%file] [%location]" />
</layout>
</appender>
Project 2 "NoDependenceLog4net
namespace NoDependenceLog4net
{
public class Program
{
static void Main(string[] args)
{
var logManager = new Log4netCommon.LogManager();
var log = logManager.GetLogger(typeof(Program));
log.Info("we are logging without reference of log4net");
log.Warn("Warn");
log.Error("Error");
Console.ReadLine();
}
}
Project 1 "Log4netCommon
namespace Log4netCommon
{
class LoggerAdapter : Log4netCommon.ILogger
{
private readonly ILog _log;
internal LoggerAdapter(ILog log)
{
_log = log;
}
public void Debug(object message)
{
_log.Debug(message);
}
public void Info(object message)
{
_log.Info(message);
}
namespace Log4netCommon
{
public class LogManager : ILogManager
{
static LogManager()
{
log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo("C:\\Users\\zxc\\Documents\\Visual Studio 2013\\Projects\\Log4netCommon\\Log4netCommon\\AppPatternLayout.config"));
}
public ILogger GetLogger(Type type)
{
var logger = log4net.LogManager.GetLogger(type);
return new LoggerAdapter(logger);
}
}
}
namespace Log4netCommon { public interface ILogManager { ILogger GetLogger(Type type); } }
"Similar" issues that I was looked
When using wrapper, how to preserve class and method name for Log4Net to log?