Skip to content

Commit

Permalink
Merge pull request #40 from litetex/develop
Browse files Browse the repository at this point in the history
Fix logging
  • Loading branch information
litetex authored Jul 7, 2020
2 parents d25a3b5 + 401e858 commit c6a9d8f
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions CoreFramework.Logging/Initalizer/Impl/DefaultLoggerInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ public DefaultLoggerInitializer(DefaultLoggerInitializerConfig config = null)

public string LogfilePath { get; protected set; }

public bool WritingToFile { get; protected set; } = false;
public bool CurrentlyWritingToFile { get; protected set; } = false;

public bool WritingToConsole { get; protected set; } = false;
public bool CurrentlyWritingToConsole { get; protected set; } = false;

protected override void DoInitialization()
{
var baseConf = GetBaseLoggerConfig();
SetLogEventLevelToLoggerConfiguration(baseConf);

// Console
if (Config.WriteConsole && !WritingToConsole)
if (Config.WriteConsole && !CurrentlyWritingToConsole)
WriteConsoleInitInfo();
if (Config.WriteConsole)
DoWriteConsole(baseConf);
Expand All @@ -43,11 +43,18 @@ protected override void DoInitialization()
if (Config.CreateLogFilePathOnStartup)
LogfilePath ??= GetLogFilePath();

if (Config.WriteFile && !WritingToFile)
WriteFileInitInfo();
if (Config.WriteFile)
{
LogfilePath ??= GetLogFilePath();

// Created parent folders
var parentFolder = Path.GetDirectoryName(Path.GetFullPath(LogfilePath));
if(!string.IsNullOrWhiteSpace(parentFolder))
Directory.CreateDirectory(parentFolder);

if (!CurrentlyWritingToFile)
WriteFileInitInfo();

DoWriteFile(baseConf);
}

Expand All @@ -59,8 +66,8 @@ protected override void DoInitialization()
if(Config.FlushOnExit)
AppDomain.CurrentDomain.ProcessExit += OnExit;

WritingToConsole = Config.WriteConsole;
WritingToFile = Config.WriteFile;
CurrentlyWritingToConsole = Config.WriteConsole;
CurrentlyWritingToFile = Config.WriteFile;
}

protected virtual LoggerConfiguration GetBaseLoggerConfig()
Expand Down Expand Up @@ -115,7 +122,7 @@ protected virtual void FinalizeInfo()
else
Log.Info("Reinitalized logging");

if (Config.WriteFile && !WritingToFile)
if (Config.WriteFile && !CurrentlyWritingToFile)
Log.Info($"Logging to file: '{LogfilePath}'");
}

Expand Down

0 comments on commit c6a9d8f

Please sign in to comment.