Closed ThomasFerro closed 7 years ago
Find my mistake, I was adding targets above the default configuration when I should be creating my own.
// Creating logging configuration
var loggingConfiguration = new LoggingConfiguration { IsEnabled = true };
#if DEBUG
// Trace everything in the debug console when running in debug mode
ChangeTraceLevel(LoggingTraceLevel.Debug);
loggingConfiguration.AddTarget(LogLevel.Trace, LogLevel.Fatal, new DebugTarget(new MyCustomLayout()));
#endif
// Creating a StreamingFileTarget target with the custom layout
var fileTarget = new StreamingFileTarget(new EPLayout());
fileTarget.FileNamingParameters.CreationMode = FileCreationMode.AppendIfExisting;
// Adding this target to the configuration
loggingConfiguration.AddTarget(LogLevel.Debug, LogLevel.Fatal, fileTarget);
// Creating a log manager with the configuration
_logManager = LogManagerFactory.CreateLogManager(loggingConfiguration);
Sorry for the inconvenience.
Hello,
I try to find a way to implement a custom layout for my traces. There is nothing about this matter in the wiki but I suppose that I just have to add my layout in the StreamingFileTarget's constructor. Here's how I create my target :
LogManagerFactory.DefaultConfiguration.AddTarget(LogLevel.Debug, LogLevel.Fatal, new StreamingFileTarget(new MyCustomLayout()) { KeepLogFilesOpenForWrite = true });
Where MyCustomLayout extends MetroLog.Layouts.Layout.
Unfortunately, even though the GetFormattedString method is called, my logs are written with the basic layout.
Is this a know issue ?