< Summary - Heimdall API

Information
Class: ArturRios.Heimdall.WebApi.LoggingConfiguration
Assembly: ArturRios.Heimdall.WebApi
File(s): /home/ci/agent/workspace/heimdall-api-docs_main/app/src/Presentation/ArturRios.Heimdall.WebApi/Registration/LoggingConfiguration.cs
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 70
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage
100%
Covered methods: 1
Fully covered methods: 1
Total methods: 1
Method coverage: 100%
Full method coverage: 100%

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Configure()100%22100%

File(s)

/home/ci/agent/workspace/heimdall-api-docs_main/app/src/Presentation/ArturRios.Heimdall.WebApi/Registration/LoggingConfiguration.cs

#LineLine coverage
 1using ArturRios.Data.Relational.Core.DependencyInjection;
 2using ArturRios.Heimdall.Shared.Retention;
 3using ArturRios.Heimdall.WebApi.Security;
 4using ArturRios.Messaging.Email;
 5using ArturRios.Util.WebApi.Configuration;
 6using ArturRios.Util.WebApi.Security.Extensions;
 7using Serilog;
 8using Serilog.Events;
 9using Serilog.Formatting.Json;
 10
 11namespace ArturRios.Heimdall.WebApi;
 12
 13internal static class LoggingConfiguration
 14{
 15    private const string LogDirectoryEnvironmentVariable = "HEIMDALL_LOG_DIRECTORY";
 16    private const string DefaultLogDirectory = "logs";
 17
 18    /// <summary>
 19    ///     Configures the console and file sinks, and bounds how long the files live (NFR-22).
 20    /// </summary>
 21    /// <remarks>
 22    ///     <para>
 23    ///         <b>The year/month directory layout is gone, deliberately.</b> The sink used to be
 24    ///         wrapped in <c>WriteTo.Map</c> keyed on <c>yyyy/MM</c>, which created a <em>new sink
 25    ///         per month</em>. A retention limit bounds the files within one sink, so it would have
 26    ///         bounded each month's directory and never removed a month — the files from the first
 27    ///         month a deployment ran were still on disk years later. A flat rolling sink with
 28    ///         <c>retainedFileTimeLimit</c> is the shape where the limit actually applies.
 29    ///     </para>
 30    ///     <para>
 31    ///         Read straight from the environment rather than through the configured options,
 32    ///         because this runs before <c>LoadConfiguration</c> — the same reason the log directory
 33    ///         is read this way. An unusable value falls back to the documented default, silently
 34    ///         here because there is no logger yet to warn with; <c>AddDataRetention</c> reads the
 35    ///         same variable later and does warn.
 36    ///     </para>
 37    ///     <para>
 38    ///         <b>Every request's client IP address is logged</b>, by Util.WebApi's
 39    ///         <c>TraceActivityMiddleware</c>, as the address the request came from — the real caller's
 40    ///         once <see cref="TrustedProxyOptions" /> names the proxy in front of the API. It is
 41    ///         security telemetry, kept for the same period as the rest of the log, and the Data
 42    ///         Retention Schedule and the Privacy Notice say so.
 43    ///     </para>
 44    ///     <para>
 45    ///         <b><c>MailgunEmailService</c> is silenced.</b> The messaging library logs every send
 46    ///         with the recipient's address in the clear — "Sending e-mail to …" and "accepted the
 47    ///         message for …" at Information, the same on a rejection at Error — which is exactly what
 48    ///         NFR-22 forbids, and this codebase's own redaction cannot reach a library's templates.
 49    ///         Nothing is lost: <c>MailgunSender</c> already logs every outcome, refusal and exception
 50    ///         included, under a <c>LogSafeEmail</c> reference.
 51    ///     </para>
 52    /// </remarks>
 53    internal static void Configure()
 54    {
 97355        var logDirectory = Environment.GetEnvironmentVariable(LogDirectoryEnvironmentVariable)
 97356                           ?? DefaultLogDirectory;
 57
 97358        var retention = DataRetentionOptions.FromEnvironment().LogRetention;
 59
 97360        Log.Logger = new LoggerConfiguration()
 97361            .MinimumLevel.Override(typeof(MailgunEmailService).FullName!, LogEventLevel.Fatal)
 97362            .WriteTo.Console(new JsonFormatter())
 97363            .WriteTo.File(
 97364                new JsonFormatter(),
 97365                Path.Combine(logDirectory, "log-.json"),
 97366                rollingInterval: RollingInterval.Day,
 97367                retainedFileTimeLimit: retention)
 97368            .CreateLogger();
 97369    }
 70}

Methods/Properties

Configure()