Quotations, orders, delivery notes, invoices and credit notes get their radars and one document screen (lines, header, transport, links, attachments) with the transformations of the engine, so a quotation reaches the invoice without retyping. The deferred invoicing groups the open delivery notes of a period by customer, payment and destination into one invoice each. Every document prints from one model: an HTML preview on screen and a PDF drawn by the in-house writer, kept among the attachments as a new version. "Invia per e-mail" proposes recipient, subject and text from the templates, attaches the PDF and hands it to a background queue that talks SMTP itself (no external library); the outcome goes to the log, section E-mail/PEC. The demo company now has a year of sales in every state, made through the engine, and run-dev.sh no longer writes to a stray B:\b folder under Git Bash. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
134 lines
5.0 KiB
C#
134 lines
5.0 KiB
C#
namespace Khaemhat.Core.Logging;
|
|
|
|
/// <summary>The sections of the application log (SPEC §9.5; mockup 084). Each module writes to its own.</summary>
|
|
public enum LogSection
|
|
{
|
|
/// <summary>Sistema.</summary>
|
|
System = 0,
|
|
|
|
/// <summary>Autenticazione.</summary>
|
|
Authentication = 1,
|
|
|
|
/// <summary>Database.</summary>
|
|
Database = 2,
|
|
|
|
/// <summary>Migrazioni.</summary>
|
|
Migrations = 3,
|
|
|
|
/// <summary>Documenti.</summary>
|
|
Documents = 4,
|
|
|
|
/// <summary>Contabilità.</summary>
|
|
Accounting = 5,
|
|
|
|
/// <summary>Magazzino.</summary>
|
|
Inventory = 6,
|
|
|
|
/// <summary>SDI/e-invoicing.</summary>
|
|
EInvoicing = 7,
|
|
|
|
/// <summary>CRM.</summary>
|
|
Crm = 8,
|
|
|
|
/// <summary>Automazioni.</summary>
|
|
Automation = 9,
|
|
|
|
/// <summary>Attività programmate.</summary>
|
|
ScheduledJobs = 10,
|
|
|
|
/// <summary>Backup.</summary>
|
|
Backup = 11,
|
|
|
|
/// <summary>API/MCP.</summary>
|
|
Api = 12,
|
|
|
|
/// <summary>E-mail/PEC.</summary>
|
|
Email = 13,
|
|
|
|
/// <summary>Integrazioni (VIES, BCE, intermediari).</summary>
|
|
Integrations = 14,
|
|
|
|
/// <summary>UI/circuiti.</summary>
|
|
Ui = 15,
|
|
|
|
/// <summary>Prestazioni.</summary>
|
|
Performance = 16,
|
|
}
|
|
|
|
/// <summary>Names, labels and the scope key of <see cref="LogSection"/>.</summary>
|
|
public static class LogSections
|
|
{
|
|
/// <summary>The scope key that carries the section (<c>using (logger.BeginScope(LogSections.Scope(...)))</c>).</summary>
|
|
public const string ScopeKey = "Section";
|
|
|
|
/// <summary>The scope key of the trace identifier.</summary>
|
|
public const string TraceIdKey = "TraceId";
|
|
|
|
/// <summary>The scope key of the user name.</summary>
|
|
public const string UserKey = "UserName";
|
|
|
|
/// <summary>The scope key of the company code.</summary>
|
|
public const string CompanyKey = "CompanyCode";
|
|
|
|
/// <summary>The scope key of the request (method and path).</summary>
|
|
public const string RequestKey = "Request";
|
|
|
|
/// <summary>The scope key of the entity concerned.</summary>
|
|
public const string EntityKey = "Entity";
|
|
|
|
/// <summary>The scope key of the entity identifier.</summary>
|
|
public const string EntityIdKey = "EntityId";
|
|
|
|
/// <summary>The Italian label shown in the log page.</summary>
|
|
/// <param name="section">The section.</param>
|
|
/// <returns>The label.</returns>
|
|
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(),
|
|
};
|
|
|
|
/// <summary>A scope state that sets the section of the events logged inside it.</summary>
|
|
/// <param name="section">The section.</param>
|
|
/// <returns>The scope state.</returns>
|
|
public static IReadOnlyList<KeyValuePair<string, object?>> Scope(LogSection section) =>
|
|
[new(ScopeKey, section.ToString())];
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
/// <param name="category">The logger category.</param>
|
|
/// <returns>The section.</returns>
|
|
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,
|
|
};
|
|
}
|