|
| 1 | +// Copyright (c) Microsoft. All rights reserved. |
| 2 | + |
| 3 | +using Serilog.Events; |
| 4 | + |
| 5 | +namespace KernelMemory.Core.Logging; |
| 6 | + |
| 7 | +/// <summary> |
| 8 | +/// Centralized constants for the logging system. |
| 9 | +/// All magic values related to logging are defined here for maintainability. |
| 10 | +/// </summary> |
| 11 | +public static class LoggingConstants |
| 12 | +{ |
| 13 | + /// <summary> |
| 14 | + /// Default maximum file size before rotation (100MB). |
| 15 | + /// Balances history retention with disk usage. |
| 16 | + /// </summary> |
| 17 | + public const long DefaultFileSizeLimitBytes = 100 * 1024 * 1024; |
| 18 | + |
| 19 | + /// <summary> |
| 20 | + /// Default number of log files to retain (30 files). |
| 21 | + /// Approximately 1 month of daily logs or ~3GB max storage. |
| 22 | + /// </summary> |
| 23 | + public const int DefaultRetainedFileCountLimit = 30; |
| 24 | + |
| 25 | + /// <summary> |
| 26 | + /// Default minimum log level for file output. |
| 27 | + /// Information level provides useful diagnostics without excessive verbosity. |
| 28 | + /// </summary> |
| 29 | + public const LogEventLevel DefaultFileLogLevel = LogEventLevel.Information; |
| 30 | + |
| 31 | + /// <summary> |
| 32 | + /// Default minimum log level for console/stderr output. |
| 33 | + /// Only warnings and errors appear on stderr by default. |
| 34 | + /// </summary> |
| 35 | + public const LogEventLevel DefaultConsoleLogLevel = LogEventLevel.Warning; |
| 36 | + |
| 37 | + /// <summary> |
| 38 | + /// Environment variable for .NET runtime environment detection. |
| 39 | + /// Takes precedence over ASPNETCORE_ENVIRONMENT. |
| 40 | + /// </summary> |
| 41 | + public const string DotNetEnvironmentVariable = "DOTNET_ENVIRONMENT"; |
| 42 | + |
| 43 | + /// <summary> |
| 44 | + /// Fallback environment variable for ASP.NET Core applications. |
| 45 | + /// Used when DOTNET_ENVIRONMENT is not set. |
| 46 | + /// </summary> |
| 47 | + public const string AspNetCoreEnvironmentVariable = "ASPNETCORE_ENVIRONMENT"; |
| 48 | + |
| 49 | + /// <summary> |
| 50 | + /// Default environment when no environment variable is set. |
| 51 | + /// Defaults to Development for developer safety (full logging enabled). |
| 52 | + /// </summary> |
| 53 | + public const string DefaultEnvironment = "Development"; |
| 54 | + |
| 55 | + /// <summary> |
| 56 | + /// Production environment name for comparison. |
| 57 | + /// Sensitive data is scrubbed only in Production. |
| 58 | + /// </summary> |
| 59 | + public const string ProductionEnvironment = "Production"; |
| 60 | + |
| 61 | + /// <summary> |
| 62 | + /// Placeholder text for redacted sensitive data. |
| 63 | + /// Used to indicate data was intentionally removed from logs. |
| 64 | + /// </summary> |
| 65 | + public const string RedactedPlaceholder = "[REDACTED]"; |
| 66 | + |
| 67 | + /// <summary> |
| 68 | + /// Human-readable output template for log messages. |
| 69 | + /// Includes timestamp, level, source context, message, and optional exception. |
| 70 | + /// </summary> |
| 71 | + public const string HumanReadableOutputTemplate = |
| 72 | + "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level:u3}] {SourceContext}: {Message:lj}{NewLine}{Exception}"; |
| 73 | + |
| 74 | + /// <summary> |
| 75 | + /// Compact output template for console (stderr) output. |
| 76 | + /// Shorter format suitable for CLI error reporting. |
| 77 | + /// </summary> |
| 78 | + public const string ConsoleOutputTemplate = |
| 79 | + "{Timestamp:HH:mm:ss} [{Level:u3}] {Message:lj}{NewLine}{Exception}"; |
| 80 | + |
| 81 | + /// <summary> |
| 82 | + /// Empty trace ID value (32 zeros) used when no Activity is present. |
| 83 | + /// Indicates no distributed tracing context is available. |
| 84 | + /// </summary> |
| 85 | + public const string EmptyTraceId = "00000000000000000000000000000000"; |
| 86 | + |
| 87 | + /// <summary> |
| 88 | + /// Empty span ID value (16 zeros) used when no Activity is present. |
| 89 | + /// Indicates no distributed tracing context is available. |
| 90 | + /// </summary> |
| 91 | + public const string EmptySpanId = "0000000000000000"; |
| 92 | +} |
0 commit comments