Skip to content

Commit

Permalink
Got Serilog logging to work
Browse files Browse the repository at this point in the history
  • Loading branch information
anban4u committed Jul 7, 2024
1 parent b92b9b9 commit 3ba5bf1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Examples/Examples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Serilog.Exceptions" Version="8.4.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.6" />
</ItemGroup>

Expand Down
21 changes: 20 additions & 1 deletion Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Configuration;

using Humanizer.Configuration;
using Serilog;
using Serilog.Exceptions;
using Serilog.Exceptions.Core;
namespace Examples
{
internal class Program
Expand Down Expand Up @@ -43,6 +46,22 @@ await Host.CreateDefaultBuilder(args)
services.AddHostedService<TestService>();

})
.ConfigureLogging(logBuilder =>
{
var logConfig = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", Serilog.Events.LogEventLevel.Information)
.Enrich.FromLogContext()
.Enrich.WithExceptionDetails()
.Enrich.WithProperty("App", Environment.GetCommandLineArgs()[0])
//.Enrich.WithMachineName()
.Enrich.WithExceptionDetails(new DestructuringOptionsBuilder().WithDefaultDestructurers())
.WriteTo.Console();

Log.Logger = logConfig.CreateLogger();

})

.Build()
.RunAsync();
}
Expand Down

0 comments on commit 3ba5bf1

Please sign in to comment.