namespace Khaemhat.Core.Logging; /// The sections of the application log (SPEC §9.5; mockup 084). Each module writes to its own. public enum LogSection { /// Sistema. System = 0, /// Autenticazione. Authentication = 1, /// Database. Database = 2, /// Migrazioni. Migrations = 3, /// Documenti. Documents = 4, /// Contabilità. Accounting = 5, /// Magazzino. Inventory = 6, /// SDI/e-invoicing. EInvoicing = 7, /// CRM. Crm = 8, /// Automazioni. Automation = 9, /// Attività programmate. ScheduledJobs = 10, /// Backup. Backup = 11, /// API/MCP. Api = 12, /// E-mail/PEC. Email = 13, /// Integrazioni (VIES, BCE, intermediari). Integrations = 14, /// UI/circuiti. Ui = 15, /// Prestazioni. Performance = 16, } /// Names, labels and the scope key of . public static class LogSections { /// The scope key that carries the section (using (logger.BeginScope(LogSections.Scope(...)))). public const string ScopeKey = "Section"; /// The scope key of the trace identifier. public const string TraceIdKey = "TraceId"; /// The scope key of the user name. public const string UserKey = "UserName"; /// The scope key of the company code. public const string CompanyKey = "CompanyCode"; /// The scope key of the request (method and path). public const string RequestKey = "Request"; /// The scope key of the entity concerned. public const string EntityKey = "Entity"; /// The scope key of the entity identifier. public const string EntityIdKey = "EntityId"; /// The Italian label shown in the log page. /// The section. /// The label. public static string Label(LogSection section) => section switch { LogSection.System => "Sistema", LogSection.Authentication => "Autenticazione", LogSection.Database => "Database", LogSection.Migrations => "Migrazioni", LogSection.Documents => "Documenti", LogSection.Accounting => "Contabilità", LogSection.Inventory => "Magazzino", LogSection.EInvoicing => "SDI/e-invoicing", LogSection.Crm => "CRM", LogSection.Automation => "Automazioni", LogSection.ScheduledJobs => "Attività programmate", LogSection.Backup => "Backup", LogSection.Api => "API/MCP", LogSection.Email => "E-mail/PEC", LogSection.Integrations => "Integrazioni", LogSection.Ui => "UI/circuiti", LogSection.Performance => "Prestazioni", _ => section.ToString(), }; /// A scope state that sets the section of the events logged inside it. /// The section. /// The scope state. public static IReadOnlyList> Scope(LogSection section) => [new(ScopeKey, section.ToString())]; /// /// The section of a logger category when no scope sets one: by namespace, so that the framework's own events land in /// a sensible place. /// /// The logger category. /// The section. public static LogSection FromCategory(string? category) => category switch { null => LogSection.System, _ when category.Contains(".Security", StringComparison.Ordinal) || category.Contains("Authentication", StringComparison.Ordinal) || category.Contains("Authorization", StringComparison.Ordinal) || category.Contains("Antiforgery", StringComparison.Ordinal) => LogSection.Authentication, _ when category.Contains("Migration", StringComparison.Ordinal) => LogSection.Migrations, _ when category.StartsWith("Khaemhat.Data", StringComparison.Ordinal) => LogSection.Database, _ when category.Contains(".Jobs", StringComparison.Ordinal) => LogSection.ScheduledJobs, _ when category.Contains(".Mail", StringComparison.Ordinal) => LogSection.Email, _ when category.Contains(".Documents", StringComparison.Ordinal) => LogSection.Documents, _ when category.StartsWith("Microsoft.AspNetCore.Components", StringComparison.Ordinal) => LogSection.Ui, _ when category.Contains("SlowQuer", StringComparison.Ordinal) || category.Contains("Performance", StringComparison.Ordinal) => LogSection.Performance, _ => LogSection.System, }; }