How Structured Logging With Serilog Can Make Your Life Easier

preview_player
Показать описание

Structured logging is a practice where you apply the same format to all your log messages. All logs will follow a similar structure, allowing them to be treated like data sets. Using structured logging, you can search and analyze your logs more than simple text.

Structured Logging In ASP.NET Core With Serilog

Join my weekly .NET newsletter:

Read my Blog here:

Subscribe for more:

Chapters
0:00 What is Structured logging?
1:12 Serilog configuration
3:45 Why you shouldn't hardcode Serilog settings
4:33 Serilog configuration through application settings
9:14 Structured logging with Serilog
11:04 How a Structured log file looks like
Рекомендации по теме
Комментарии
Автор

Hi Milan. I recently discovered your channel and appreciate your extent of coverage in chosen topics.

I also greatly appreciate how you separate the chapters/sections so I don't pause the video early on and look for "not hardcoing serilog config in programcs" elsewhere; because you've made it clear that it was covered in a future chapter.

Cheers!

KarthikS
Автор

Interesting video, I love serilog. If you can make a video on serilog + elastic search (from a sink) + kibana (also from a sink), it would be pretty sick :)

samerelsahih
Автор

I really like Serilog. I started to use it in 2019. It has been really helpful and saved me a lot of debugging time. Thank you for adapting it to modern technology.

StephaneDroletGolf
Автор

I have just switched to serilog - I was using your video as starting point, so thank you. Hence I am by far no expert of the field. I have found cumbersome to work with the array-style configuration, especially when overriding from environment - as it needs indexing. There is however - since quite a while actually - a syntax that allows to use an object with descriptive keys instead. This takes advantage of how the configuration infrastructure works in dotnet. And the cool part is, that you can leverage this even further by compacting the overrides in environment-specific appsettings. Like this for example:

{
"retainedFileCountLimit": 1,
"RollingInterval": "Infinite",
"formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog"
},

Quite simpler than providing the whole structure.

zoltanzorgo
Автор

I was hoping you would show the details on using SQL Server and how to log to it, such as auto-creation of a log table, the columns to includes, etc. Maybe a future video??

LesGainous
Автор

Milan, do you have the creation process of full projects on video? or even in a course? I'm a big fan of learning through doing ant not just watching, and watching you and repeating the process of building a complete project applying some patterns, principles and good practices, would be amazing, I would pay to see that and learn from your experience.

eduardrivas
Автор

I would suggest to add Request ID to logs and make them async configuring WriteTo to be async.

pagorbunov
Автор

Nice Video. Which theme are you using? Your color scheme are better and difference than as usual visual studio provides as default.

salmanshafiq
Автор

i've a question. I can put this logs in each endpoint? For example, I've a endpoint to update one list and when this list update create a log

theeusftn
Автор

Hi Milan, I really enjoy your works, i mean you have demonstrated how easy it is to adapt to any programing construct.
Please do you have a repo for these source codes.
Thnk you again

adahadapato
Автор

I like to use preprocessors for my debug code. I can remove most of my debug code very easy once I'm done making changes. And then like he does I keep the warning and error debug active just by switching my define from "debug_verbose" to "debug_performance".

betterlifeexe
Автор

I was hoping you would connect it to a seq sink.

Is seq usually used in the industry a lot?

ZukoTheShinigami
Автор

This is good but it also feels a bit light. For instance - in a production environment you'd implement masking on sensitive fields. I've tried 3 different libraries and NONE seem to remove the password and ssn correctly - from either the request logging or the global exception handler. For the time being I set that aside because I'm so annoyed with it.

nevernerd
Автор

Great Video, Thank you, i have a question here, i see that you have set the Default loglevel to Information yet in the end of the video we can see in the log.text file debug logs being logged, why is that? Am i missing something here?

savithapn
Автор

Thank you so much. Is it OK to have the logs in a database? And how so?

codeme
Автор

Thanks for this.
What about implementing Structured logging, using Serilog without the MediatR library? Do you have any good sources for this?

zaharivaklinov
Автор

hey milan!! its great.. but i need logs to print in seperate folders for each controller. can you please help me out or make another video about serilog with indepth configurations. thanks 👍

ammarahmed
Автор

plz add relative video links in description. If we didn't watch then we can able to watch it.(You said previous video but which video we can't find in description or (i) button.)

salmanshafiq
Автор

Hi Milan,

I came across with this exact configuration you are presenting here, however, I notice the logs are not show in the output window but in the console of the program itself. Looks like there is a specific configuration (Writeto(debug)). My question is, How did you manage to get those logs in the output window with the congiguration shown in this video?, Do you have additional settings in your debug pane from VS?

Thanks in advance!

johanngodinezquezada
Автор

Great video as always Milan.

One question. I want more serious error logs to be written both in the console and in the file, but less important logs like information and events only to the console. How can I do that?

jj