Version 3.0.337

This commit is contained in:
Anja Müller-Meißner 2022-08-30 15:42:25 +02:00
parent fd0e63cf10
commit 573fe77e12
2336 changed files with 33688 additions and 86082 deletions

View file

@ -15,6 +15,6 @@ namespace TINK.Model.Logging
/// <summary> Gets path where log files are located. </summary>
/// <returns>Path to log files.</returns>
public string LogFilePath { get { return string.Empty; } }
public string LogFilePath { get { return string.Empty; } }
}
}

View file

@ -1,5 +1,5 @@
using Serilog;
using System;
using System;
using Serilog;
using TINK.Repository.Exception;
namespace TINK.Model.Logging

View file

@ -1,9 +1,9 @@
using Serilog;
using Serilog.Configuration;
using Serilog.Formatting.Json;
using System;
using System;
using System.Collections.Generic;
using System.IO;
using Serilog;
using Serilog.Configuration;
using Serilog.Formatting.Json;
namespace TINK.Model.Logging
{
@ -17,6 +17,12 @@ namespace TINK.Model.Logging
/// <summary> Provides logging file name helper functionality.</summary>
public static class LoggerConfigurationHelper
{
// Max count of retained logs count.
private const int RETAINEDFILECOUNT = 10;
// Max size of logging file.
private const int MAXLOGFILESSIZEBYTESBYTES = 1024 * 1024 * 8; // 8MB
/// <summary> Holds the log file name. </summary>
private static ILoggingDirectoryManager DirectoryManager { get; set; } = new EmptyDirectoryLoggingManger();
@ -30,7 +36,7 @@ namespace TINK.Model.Logging
this LoggerSinkConfiguration loggerConfiguration,
string logFileFolder,
RollingInterval rollingInterval = RollingInterval.Session,
int retainedFilesCountLimit = 10)
int retainedFilesCountLimit = RETAINEDFILECOUNT)
{
if (DirectoryManager is EmptyDirectoryLoggingManger)
{
@ -67,9 +73,10 @@ namespace TINK.Model.Logging
return null;
}
return loggerConfiguration.File(
return loggerConfiguration.File(
new JsonFormatter(),
DirectoryManager.LogFileName,
fileSizeLimitBytes: MAXLOGFILESSIZEBYTESBYTES / RETAINEDFILECOUNT,
/*shared: true, // Leads to exception if activated.*/
rollingInterval: Serilog.RollingInterval.Infinite,
retainedFileCountLimit: retainedFilesCountLimit);
@ -78,7 +85,7 @@ namespace TINK.Model.Logging
/// <summary> Gets all log files in logging directory. </summary>
/// <param name="p_oLogger"></param>
/// <returns>List of log files.</returns>
public static IList<string> GetLogFiles(this ILogger p_oLogger)
public static IList<string> GetLogFiles(this ILogger p_oLogger)
{
try
{

View file

@ -13,34 +13,34 @@ namespace TINK.Model.Logging
private LoggingDirectoryManager() { }
public LoggingDirectoryManager(
Func<string, IList<string>> p_oFileListProvider,
Func<string, bool> p_oDirectoryExistsChecker,
Action<string> p_oDirectoryCreator,
Action<string> p_oFileEraser,
string p_oLogFilePath,
char p_strDirectorySeparatorChar,
Func<string, IList<string>> fileListProvider,
Func<string, bool> directoryExistsChecker,
Action<string> directoryCreator,
Action<string> fileEraser,
string logFilePath,
char directorySeparatorChar,
int p_iRetainedFilesCountLimit)
{
m_oFileListProvider = p_oFileListProvider ?? throw new ArgumentException($"Can not instantiate {nameof(LoggingDirectoryManager)}- object. File list provider delegate can not be null.");
m_oFileListProvider = fileListProvider ?? throw new ArgumentException($"Can not instantiate {nameof(LoggingDirectoryManager)}- object. File list provider delegate can not be null.");
if (p_oDirectoryExistsChecker == null)
if (directoryExistsChecker == null)
{
throw new ArgumentException($"Can not instantiate {nameof(LoggingDirectoryManager)}- object. Directory existance checker delegate can not be null.");
}
if (p_oDirectoryCreator == null)
if (directoryCreator == null)
{
throw new ArgumentException($"Can not instantiate {nameof(LoggingDirectoryManager)}- object. Directory creator delegate can not be null.");
}
m_oFileEraser = p_oFileEraser ?? throw new ArgumentException($"Can not instantiate {nameof(LoggingDirectoryManager)}- object. File eraser delegate can not be null.");
m_oFileEraser = fileEraser ?? throw new ArgumentException($"Can not instantiate {nameof(LoggingDirectoryManager)}- object. File eraser delegate can not be null.");
if (string.IsNullOrEmpty(p_oLogFilePath))
if (string.IsNullOrEmpty(logFilePath))
{
throw new ArgumentException($"Can not instantiate {nameof(LoggingDirectoryManager)}- object. Log file path can not be null or empty.");
}
if (string.IsNullOrEmpty(p_strDirectorySeparatorChar.ToString()))
if (string.IsNullOrEmpty(directorySeparatorChar.ToString()))
{
throw new ArgumentException($"Can not instantiate {nameof(LoggingDirectoryManager)}- object. Directory separtor character can not be null or empty.");
}
@ -50,9 +50,9 @@ namespace TINK.Model.Logging
throw new ArgumentException($"Can not instantiate {nameof(LoggingDirectoryManager)}- object. Count of retained log files is {p_iRetainedFilesCountLimit} but must be equal or larger one.");
}
DirectorySeparatorChar = p_strDirectorySeparatorChar.ToString();
DirectorySeparatorChar = directorySeparatorChar.ToString();
LogFilePath = $"{p_oLogFilePath}{DirectorySeparatorChar}{LOGDIRECTORYTITLE}";
LogFilePath = $"{logFilePath}{DirectorySeparatorChar}{LOGDIRECTORYTITLE}";
m_iRetainedFilesCountLimit = p_iRetainedFilesCountLimit;
@ -63,11 +63,11 @@ namespace TINK.Model.Logging
}
// Create directory if direcotry does not exist.
if (p_oDirectoryExistsChecker(LogFilePath) == false)
if (directoryExistsChecker(LogFilePath) == false)
{
try
{
p_oDirectoryCreator(LogFilePath);
directoryCreator(LogFilePath);
}
catch (Exception l_oException)
{
@ -83,9 +83,9 @@ namespace TINK.Model.Logging
var l_oExceptions = new List<Exception>();
var l_oSortedFileArray = m_oFileListProvider(LogFilePath).OrderByDescending(x => x).ToArray();
for (int l_iIndex = l_oSortedFileArray.Length - 1;
l_iIndex >= m_iRetainedFilesCountLimit - 1; /* files remaining count must be m_iRetainedFilesCountLimit - 1 because new log file will be added afterwards */
l_iIndex --)
for (int l_iIndex = l_oSortedFileArray.Length - 1;
l_iIndex >= m_iRetainedFilesCountLimit - 1; /* files remaining count must be m_iRetainedFilesCountLimit - 1 because new log file will be added afterwards */
l_iIndex--)
{
try
{