This commit is contained in:
2022-12-16 12:59:34 +01:00
parent 5d3c85ffd3
commit 795f9807d5
8 changed files with 96 additions and 48 deletions

View File

@@ -1,7 +1,9 @@
using Microsoft.Extensions.DependencyInjection;
using EonaCat.Logger.Helpers;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System;
using System.Runtime;
namespace EonaCat.Logger.Extensions
{

View File

@@ -126,9 +126,8 @@ namespace EonaCat.Logger
System.IO.StreamWriter file = new System.IO.StreamWriter(LogFile, true);
foreach (LogMessage item in group)
{
file.WriteAsync(item.Message);
file.Write(item.Message);
}
file.Close();
completed = true;
}

View File

@@ -1,8 +1,9 @@
using EonaCat.logger.Managers;
using EonaCat.Logger.Managers;
using EonaCatLogger.EonaCatCoreLogger.Models;
using Microsoft.Extensions.Logging;
using System;
using System.Text;
using System.Runtime;
namespace EonaCat.Logger.Internal
{
@@ -48,6 +49,19 @@ namespace EonaCat.Logger.Internal
}
_provider.AddMessage(timestamp, message);
var EonaCatMessage = new EonaCatLogMessage
{
DateTime = timestamp.DateTime,
Message = message,
LogType = logLevel.FromLogLevel()
};
if (_loggerSettings != null)
{
EonaCatMessage.Origin = string.IsNullOrWhiteSpace(_loggerSettings.LogOrigin) ? "BatchingLogger" : _loggerSettings.LogOrigin;
_loggerSettings?.OnLogEvent(EonaCatMessage);
}
}
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)

View File

@@ -54,16 +54,21 @@ namespace EonaCat.Logger.Internal
if (_currentBatch.Count > 0)
{
bool isBatchWritten = false;
try
{
await WriteMessagesAsync(_currentBatch, _cancellationTokenSource.Token);
isBatchWritten = true;
}
catch
{
// ignored
}
_currentBatch.Clear();
if (isBatchWritten)
{
_currentBatch.Clear();
}
}
await IntervalAsync(_interval, _cancellationTokenSource.Token);

View File

@@ -12,6 +12,7 @@ namespace EonaCatLogger.EonaCatCoreLogger.Models
public DateTime DateTime { get; set; }
public string Message { get; set; }
public ELogType LogType { get; set; }
public string Origin { get; set; }
public override string ToString()
{