Skip to content

Instantly share code, notes, and snippets.

@larenelg
Created May 3, 2022 07:15
Show Gist options
  • Save larenelg/79a135be014bf3699ff30d0d3c075735 to your computer and use it in GitHub Desktop.
Save larenelg/79a135be014bf3699ff30d0d3c075735 to your computer and use it in GitHub Desktop.
CSSE6400 Code Snippets to Add for Logging

WeatherApi.csproj

<PackageReference Include="serilog" Version="2.10.0" />
<PackageReference Include="serilog.AspNetCore" Version="5.0.0" />
<PackageReference Include="serilog.sinks.console" Version="4.0.1" />
<PackageReference Include="serilog.sinks.seq" Version="5.1.1" />

appsettings.json

"SeqUrl": "http://localhost:5341",
"SeqApiKey": ""

Program.cs

using Serilog;

...

// Setup configuration getter.
var configuration = builder.Configuration;

...

var loggingConfig = configuration.GetSection("Logging");
var seqUrl = loggingConfig["SeqUrl"];
var seqApiKey = loggingConfig["SeqApiKey"];

builder.Host.UseSerilog((ctx, lc) => lc
    .MinimumLevel.Information()
    .Enrich.FromLogContext()
    .WriteTo.Console()
    .WriteTo.Seq(seqUrl, apiKey: seqApiKey)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment