aspnet / Logging

[Archived] Common logging abstractions and a few implementations. Project moved to https://github.com/aspnet/Extensions
Apache License 2.0
506 stars 248 forks source link

FileLoggerProvider optimisation #942

Closed ghost closed 5 years ago

ghost commented 5 years ago

I think that FileLoggerProvider lacks of optimisation.

1) It tries to roll files on every WriteMessagesAsync method call (redundant).

2) It does not write any messages if the file size for the day exceeds the limit. (loss of last messages)

if (_maxFileSize > 0 && fileInfo.Exists && fileInfo.Length > _maxFileSize)
{
                    return;
}

3) It waits on interval even if there are still a lot of messages in the queue. (waste of time to process messages)

await IntervalAsync(_interval, _cancellationTokenSource.Token);

I have made optimisations for this (fixed this issues in my implementation)

https://github.com/BBGONE/JRIApp.Core/blob/master/DEMOS/RIAppDemoMVC/Extensions.Logging.RollingFile/FileLoggerProvider.cs

https://github.com/BBGONE/JRIApp.Core/blob/master/DEMOS/RIAppDemoMVC/Extensions.Logging.RollingFile/Internal/BatchingLoggerProvider.cs

You could copy them into your implementations:

https://github.com/aspnet/Logging/blob/master/src/Microsoft.Extensions.Logging.AzureAppServices/Internal/FileLoggerProvider.cs

https://github.com/aspnet/Logging/blob/master/src/Microsoft.Extensions.Logging.AzureAppServices/Internal/BatchingLoggerProvider.cs

ghost commented 5 years ago

Oops, it was archived