|
Hello,
I am having trouble with logging from different classes into separate files. I have DLL, which uses NLog, and application, which uses also NLog, but also the DLL. So when the application starts, it logs events into the right file, but when the application starts the DLL, the logging events from the application are logged into the file specified in the DLL NLog settings. Weird, right?
This is how I log the events from the application:
private static NLog.Logger logger;
public static void InitLogger()
{
// set NLog
logger = LogManager.GetLogger("DeviceManager");
LoggingConfiguration config = new LoggingConfiguration();
FileTarget fileTarget = new FileTarget();
config.AddTarget("file", fileTarget);
// Step 3. Set target properties
fileTarget.FileName = "C:/ManagerLog/" + String.Format("{0:yyyy-MM-dd-hh-mm-ss}", DateTime.Now) + ".txt";
fileTarget.Layout = "${longdate} | ${level:padding=7} | ${message}";
// Step 4. Define rules
LoggingRule rule2 = new LoggingRule("*", LogLevel.Trace, fileTarget);
config.LoggingRules.Add(rule2);
// Step 5. Activate the configuration
LogManager.Configuration = config;
}
public static void Log(string message)
{
if (logger == null) InitLogger();
logger.Trace(message);
}
and this is how I init and log events in the DLL:
// set NLog
Logger logger = LogManager.GetLogger("Payout");
LoggingConfiguration config = new LoggingConfiguration();
FileTarget fileTarget = new FileTarget();
config.AddTarget("file", fileTarget);
// Step 3. Set target properties
fileTarget.FileName = "C:/PayoutLog/" + String.Format("{0:yyyy-MM-dd-hh-mm-ss}", DateTime.Now) + ".txt";
fileTarget.Layout = "${longdate} | ${level:padding=7} | ${stacktrace:topFrames=8:padding=250} | ${message}";
// Step 4. Define rules
LoggingRule rule2 = new LoggingRule("*", LogLevel.Trace, fileTarget);
config.LoggingRules.Add(rule2);
// Step 5. Activate the configuration
LogManager.Configuration = config;
- the only difference is in getLogger(), fileName and layout.
So the question is, why NLog does not log into separate files - anyone knows whats wrong, and how can I solve this? Thanks for reply
|