Example of Enriching Logs with Serilog? #1803
Replies: 13 comments 1 reply
-
What's aspire specific about serilog enrichment? |
Beta Was this translation helpful? Give feedback.
-
The Host, and then how to make all of your services use shared configuration for serilog since the extension method doesn't have access to the IHost. |
Beta Was this translation helpful? Give feedback.
-
Ah I see, you're asking about the extension methods that only support IHostApplicationBuidler and not IHostBuilder. For serilog, you might need to use the other method of wiring it up. https://github.com/serilog/serilog-extensions-logging cc @eerhardt |
Beta Was this translation helpful? Give feedback.
-
Can you call |
Beta Was this translation helpful? Give feedback.
-
you need more than that. You have to create the root log something like this:
Before that call won't error. Which has to happen for every microservice. Then you have to add something like this:
But I still can't get the host to just output serilog messages even when I set that up on the host program.cs. It works fine for the microservices though. (and I just created a shared static class that creates the slimbuilder and does the log stuff at the beginning and then put the AddSerialog in the extension method. Was hoping there was a more elegant way, or something I was missing. |
Beta Was this translation helpful? Give feedback.
-
You mean the AppHost.csproj's Program.cs? Is there a reason you want to "enrich" this log? This project isn't technically part of your app - it doesn't get deployed to the cloud. It is more of an "orchestrator" project to tell the tooling which microservice projects and containers to spin up. |
Beta Was this translation helpful? Give feedback.
-
It generates noise like crazy that is scrolling by endlessly and since I use serilog everywhere else I was hoping to use it to silence what doesn't seem to silence by setting the loglevel in the appsettings.config |
Beta Was this translation helpful? Give feedback.
-
I'm confused about this too. Can you help us understand why serilog on the apphost project is important? |
Beta Was this translation helpful? Give feedback.
-
The host when it runs opens a new terminal and spews stuff like this:
Pretty much continuously. In my configuration I have this:
Which is being ignored. And the host for Aspire doesn't have access to the Logging stuff that the rest of the IHost extensions have. |
Beta Was this translation helpful? Give feedback.
-
@JohnGalt1717 inside builder.Services.AddSerilog(configuration =>
{
configuration.MinimumLevel.Override("Aspire.Hosting.Dcp", LogEventLevel.Warning);
configuration.WriteTo.Console();
}); Are you referring to the The bootstrap logger works for me too: Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateBootstrapLogger();
builder.Services.AddSerilog(configuration =>
{
configuration.MinimumLevel.Override("Aspire.Hosting.Dcp", LogEventLevel.Warning);
configuration.WriteTo.Console();
});
Log.Information("Aspire.Host has started")
|
Beta Was this translation helpful? Give feedback.
-
I guess i don't see the purpose of using serilog in the host. Why does this matter? Or is this just a question about how one would ago about doing that just generally? |
Beta Was this translation helpful? Give feedback.
-
I'm struggling to get SeriLog and Aspire structured logs work together. |
Beta Was this translation helpful? Give feedback.
-
The serilog/serilog-aspnetcore#359 approach works. But the reason to pick Serilog is that the ILogger implementation in Microsoft.Extensions.Logging doesn't really give you structured logging. You have to serialize complex types first. In .NET Aspire, ServiceDefaults project, Extensions class, method ConfigureOpenTelemetry, there is this call:
Can this be configured for structured logging? So that you don't have to add Serilog or another external provider. |
Beta Was this translation helpful? Give feedback.
-
Is there any guidance on this? How should this be implemented?
Beta Was this translation helpful? Give feedback.
All reactions