Added LocalTime or UTC time display
This commit is contained in:
@@ -4,7 +4,6 @@ using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using EonaCat.Logger.EonaCatCoreLogger;
|
||||
@@ -16,6 +15,7 @@ namespace EonaCat.Logger.Managers
|
||||
{
|
||||
public partial class LogManager : ILogManager, IDisposable
|
||||
{
|
||||
private DateTime CurrentDateTme => Settings.UseLocalTime ? DateTime.Now : DateTime.UtcNow;
|
||||
private DateTime _logDate;
|
||||
public ILoggerProvider LoggerProvider { get; private set; }
|
||||
public ILoggerFactory LoggerFactory { get; private set; }
|
||||
@@ -30,7 +30,7 @@ namespace EonaCat.Logger.Managers
|
||||
|
||||
public static LogManager Instance => InstanceInit();
|
||||
|
||||
public LoggerSettings Settings { get; } = CreateDefaultSettings();
|
||||
public LoggerSettings Settings { get; set; } = CreateDefaultSettings();
|
||||
|
||||
private static LogManager InstanceInit()
|
||||
{
|
||||
@@ -62,9 +62,7 @@ namespace EonaCat.Logger.Managers
|
||||
if (_tokenSource.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
DateTime now = DateTime.UtcNow;
|
||||
|
||||
if (IsRunning && now.Date > _logDate.Date)
|
||||
if (IsRunning && CurrentDateTme.Date > _logDate.Date)
|
||||
await StopLoggingAsync().ConfigureAwait(false);
|
||||
|
||||
IsRunning = true;
|
||||
@@ -73,7 +71,7 @@ namespace EonaCat.Logger.Managers
|
||||
|
||||
Directory.CreateDirectory(Settings.FileLoggerOptions.LogDirectory);
|
||||
|
||||
_logDate = now;
|
||||
_logDate = CurrentDateTme;
|
||||
}
|
||||
|
||||
private void CreateLogger()
|
||||
@@ -91,6 +89,7 @@ namespace EonaCat.Logger.Managers
|
||||
configuration.LogDirectory = fileLoggerOptions.LogDirectory;
|
||||
configuration.FileNamePrefix = fileLoggerOptions.FileNamePrefix;
|
||||
configuration.MaxRolloverFiles = fileLoggerOptions.MaxRolloverFiles;
|
||||
configuration.UseLocalTime = Settings.UseLocalTime;
|
||||
}));
|
||||
|
||||
var serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
@@ -172,7 +171,7 @@ namespace EonaCat.Logger.Managers
|
||||
{
|
||||
AppDomain.CurrentDomain.ProcessExit += ProcessExit;
|
||||
Console.CancelKeyPress += Console_CancelKeyPress;
|
||||
_logDate = DateTime.UtcNow;
|
||||
_logDate = CurrentDateTme;
|
||||
}
|
||||
|
||||
private void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
|
||||
@@ -188,7 +187,7 @@ namespace EonaCat.Logger.Managers
|
||||
private Task StopLoggingAsync()
|
||||
{
|
||||
IsRunning = false;
|
||||
InternalWriteAsync(DateTime.UtcNow, $"{DllInfo.ApplicationName} stopped.");
|
||||
InternalWriteAsync(CurrentDateTme, $"{DllInfo.ApplicationName} stopped.");
|
||||
return Task.Delay(500);
|
||||
}
|
||||
|
||||
@@ -217,12 +216,10 @@ namespace EonaCat.Logger.Managers
|
||||
if (logType == ELogType.NONE)
|
||||
return;
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
if (!IsRunning)
|
||||
StartNewLogAsync().ConfigureAwait(false);
|
||||
|
||||
InternalWriteAsync(now, message, logType, writeToConsole);
|
||||
InternalWriteAsync(CurrentDateTme, message, logType, writeToConsole);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user