Files
EonaCat.Logger/EonaCat.Logger/EonaCatCoreLogger/FileLoggerOptions.cs
2026-02-13 15:46:30 +01:00

120 lines
3.9 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using EonaCat.Logger.EonaCatCoreLogger.Internal;
using EonaCat.Logger.Managers;
using Microsoft.Extensions.Logging;
namespace EonaCat.Logger.EonaCatCoreLogger;
// This file is part of the EonaCat project(s) which is released under the Apache License.
// See the LICENSE file or go to https://EonaCat.com/License for full license details.
/// <summary>
/// Options for file logging.
/// </summary>
public class FileLoggerOptions : BatchingLoggerOptions
{
private int _fileSizeLimit = 200 * 1024 * 1024;
private int _maxRolloverFiles = 10;
private int _retainedFileCountLimit = 50;
public bool EnableCategoryRouting { get; set; }
public ELogType MinimumLogLevel { get; set; } = ELogType.INFO;
public string Category { get; set; }
public byte[] EncryptionKey { get; set; }
public byte[] EncryptionIV { get; set; }
public bool IsEncryptionEnabled => EncryptionKey != null && EncryptionIV != null;
public static string DefaultPath =>
AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory;
/// <summary>
/// Gets or sets a strictly positive value representing the maximum log size in bytes or null for no limit.
/// Once the log is full, no more messages will be appended.
/// Defaults to <c>200MB</c>.
/// </summary>
public int FileSizeLimit
{
get => _fileSizeLimit;
set
{
if (value <= 0)
{
throw new ArgumentOutOfRangeException(nameof(value), $"{nameof(FileSizeLimit)} must be positive.");
}
_fileSizeLimit = value;
}
}
/// <summary>
/// Gets or sets a strictly positive value representing the maximum retained file count or null for no limit.
/// Defaults to <c>50</c>.
/// </summary>
public int RetainedFileCountLimit
{
get => _retainedFileCountLimit;
set
{
if (value <= 0)
{
throw new ArgumentOutOfRangeException(nameof(value),
$"{nameof(RetainedFileCountLimit)} must be positive.");
}
_retainedFileCountLimit = value;
}
}
/// <summary>
/// Gets or sets the max times to try to write to the file.
/// Defaults 3.
/// </summary>
public int MaxWriteTries { get; set; } = 3;
/// <summary>
/// Determines if we need to use the local time in the logging or UTC (default:false)
/// </summary>
public bool UseLocalTime { get; set; }
/// <summary>
/// Gets or sets a strictly positive value representing the maximum retained file rollovers or null for no limit.
/// Defaults to <c>10</c>.
/// </summary>
public int MaxRolloverFiles
{
get => _maxRolloverFiles;
set
{
if (value <= 0)
{
throw new ArgumentOutOfRangeException(nameof(value), $"{nameof(MaxRolloverFiles)} must be positive.");
}
_maxRolloverFiles = value;
}
}
/// <summary>
/// Gets or sets the filename prefix to use for log files.
/// Defaults to <c>EonaCat_</c>.
/// </summary>
public string FileNamePrefix { get; set; } = "EonaCat";
/// <summary>
/// The directory in which log files will be written, relative to the app process.
/// Default to <c>executablePath\logs</c>
/// </summary>
/// <returns></returns>
public string LogDirectory { get; set; } = Path.Combine(DefaultPath, "logs");
/// <summary>
/// Determines if we need to include the correlation ID in the log (default: false)
/// </summary>
public bool IncludeCorrelationId { get; set; }
public LoggerSettings Settings { get; internal set; }
public LoggerSettings LoggerSettings { get; internal set; }
}