Reputation: 549
I instantiate the logger in every class I want to log like this
private static Logger logger = LogManager.GetCurrentClassLogger();
Then I created a static class with multiple helper functions for logging passing the logger object.
Example of a simple one:
public static void LogMessage(Logger logger, LogLevel logLevel, string message)
{
StringBuilder logMessage = new StringBuilder();
logMessage.AppendLine("Message: " + message);
logger.Log(logLevel, logMessage);
}
The problem is even if I created the logger in another class, it logs the name of the current class (the static one). I can see the name of the logger in the property list and it has the right name (the name of the class it's been instantiated) when calling the log method. I tried to pass the logger as ref, but it does the same thing.
Does anyone knows why this happens?
Upvotes: 1
Views: 1145
Reputation: 36849
This is expected behavior. There are some solutions:
LogManager.GetLogger("loggername")
and pass your name, orLogTo.Debug("TheMessage");
Upvotes: 1