Skip to content

Fix Serilog misconfiguration: silence, unstructured logs, and missing File sink#33

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-serilog-misconfiguration
Draft

Fix Serilog misconfiguration: silence, unstructured logs, and missing File sink#33
Copilot wants to merge 3 commits intomainfrom
copilot/fix-serilog-misconfiguration

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 12, 2026

Three Serilog misconfigurations in Program.cs caused all Information-level startup logs to be silenced, produced unstructured log output, and left no persistent log trail.

Changes

  • MinimumLevel: WarningInformation — allows startup Log.Information(...) calls to emit
  • File sink: Added rolling daily file sink via Serilog.Sinks.File v6.0.0 for persistent log retention
  • Structured logging: Fixed interpolated string to use a named message template property
// Before
.MinimumLevel.Warning()
.WriteTo.Console()
// ...
Log.Information($"Using SQLite database at: {sqlitePath}");

// After
.MinimumLevel.Information()
.WriteTo.Console()
.WriteTo.File("logs/mythapi-.log", rollingInterval: RollingInterval.Day)
// ...
Log.Information("Using SQLite database at: {SqlitePath}", sqlitePath);
Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug] Serilog misconfiguration in Program.cs silences logs and breaks structured logging</issue_title>
<issue_description>## Description
The Serilog configuration in Program.cs has three critical issues that cause log entries to be silenced and violate structured logging best practices.

Issue 1: MinimumLevel set to Warning swallows all Information logs

MinimumLevel.Warning() is configured, meaning all Log.Information(...) calls scattered throughout Program.cs are never emitted — including startup messages, database selection info, and schema creation confirmations.

Issue 2: String interpolation instead of structured logging templates

Several log calls use C# string interpolation ($"...") instead of Serilog's message templates, which defeats structured logging and breaks log querying:

// ❌ Current — plain string, no structured properties
Log.Information($"Using SQLite database at: {sqlitePath}");

// ✅ Expected — structured template with named property
Log.Information("Using SQLite database at: {SqlitePath}", sqlitePath);

Issue 3: Only the Console sink is configured

No secondary/persistent sink (e.g. File) is configured, meaning all logs are lost after a process restart. The org logging guidelines recommend at least a File sink for non-development environments.

Steps to Reproduce

  1. Run the application with ASPNETCORE_ENVIRONMENT=Development
  2. Observe no Information-level startup messages appear in the console output

Expected Behavior

  • All Log.Information(...) calls in Program.cs emit to the console
  • Log messages use structured templates (e.g. "Using SQLite database at: {SqlitePath}")
  • A File sink is configured for persistent log retention

Actual Behavior

  • MinimumLevel.Warning() silences all Information log entries
  • Interpolated strings produce unstructured log messages
  • Logs are console-only and lost on restart

Environment

  • .NET 8.0
  • Serilog (ASP.NET Core integration via builder.Host.UseSerilog())

Proposed Fix

In Program.cs:

Log.Logger = new LoggerConfiguration()
    .Enrich.FromLogContext()
    .Enrich.WithProperty("Application", "MythApi")
    .Enrich.WithProperty("Environment", Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production")
    .MinimumLevel.Information()                          // ✅ Allow Information logs
    .WriteTo.Console()
    .WriteTo.File("logs/mythapi-.log", rollingInterval: RollingInterval.Day)  // ✅ Add File sink
    .CreateLogger();

Fix interpolated calls:

// Before
Log.Information($"Using SQLite database at: {sqlitePath}");

// After
Log.Information("Using SQLite database at: {SqlitePath}", sqlitePath);

Acceptance Criteria

  • MinimumLevel changed from Warning to Information
  • All Log.Information($"...") calls converted to structured message templates
  • A rolling File sink added to the Serilog configuration
  • All existing Log.Information startup messages are visible in console output when running the application
    </issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 2 commits March 12, 2026 10:46
Co-authored-by: aatmmr <15815012+aatmmr@users.noreply.github.com>
…ile sink

Co-authored-by: aatmmr <15815012+aatmmr@users.noreply.github.com>
Copilot AI changed the title [WIP] [Bug] Fix Serilog misconfiguration in Program.cs Fix Serilog misconfiguration: silence, unstructured logs, and missing File sink Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Serilog misconfiguration in Program.cs silences logs and breaks structured logging

2 participants