Files
EonaCat.Logger/EonaCat.Logger/EonaCatCoreLogger/FileLoggerOptions.cs
2026-02-12 20:54:24 +01:00

158 lines
5.3 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 mask certain keywords
/// </summary>
public bool UseMask { get; set; }
/// <summary>
/// Determines the keywords to mask
/// </summary>
public List<string> MaskedKeywords { get; set; } = new List<string>();
public string Mask { get; set; } = "***MASKED***";
/// <summary>
/// Determines that if masking is enabled we also need to use the default masking options:
/// IP addresses
/// MAC addresses
/// Emails
/// Passwords
/// Credit card numbers
/// Social security numbers (SSN) and BSN (Dutch Citizen Service Number)
/// API keys/tokens
/// Phone numbers (generic and Dutch specific)
/// Dates of birth (DOB) or other date formats
/// IBAN/Bank account numbers (generic and Dutch specific)
/// JWT tokens
/// URLs with sensitive query strings
/// License keys
/// Public and private keys (e.g., PEM format)
/// Dutch KVK number (8 or 12 digits)
/// Dutch BTW-nummer (VAT number)
/// Dutch driving license number (10-12 characters)
/// Dutch health insurance number (Zorgnummer)
/// Other Dutch Bank Account numbers (9-10 digits)
/// Dutch Passport Numbers (9 alphanumeric characters
/// Dutch Identification Document Numbers (varying formats)
/// Custom keywords specified in LoggerSettings
/// </summary>
public bool UseDefaultMasking { get; set; } = true;
/// <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; }
}