'Stop Using Structured Logging in .NET!' | Code Cop #006

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

Hello everybody, I'm Nick, and in this video, I'll show you why structured logging is so useful and why the advice given on a LinkedIn post is absolutely terrible. Following such advice can waste a lot of app memory leading to a poorly performing app but also make it harder for you to debug your application.

Don't forget to comment, like and subscribe :)

Social Media:

#csharp #dotnet
Рекомендации по теме
Комментарии
Автор

One of the problems with the string concatenation method is that it is done everytime. Imagine if the logging level was set to Warning so that information message are not routinely logged. WIth the string concatenation method you would be building up this string but not using it. Whereas with the template method you would call the logger with a string constant and it would immediately return because it's not interested in logging at that level.

steve-wright-uk
Автор

Searching logs for a fix template is also incredibly useful. Filtering JSON logs when concatenated values are used is a nightmare.

lorcaranr
Автор

Funny, I fight in PRs to use structured logging and get rid of string concatenation or string interpolation, those guys are ruining my mission!
Although, I fight for different reasons, I don't care about memory efficiency here because for me it's negligible - just want to have useful logs to save developer's time.

proosee
Автор

Glad to see I haven't been missing out on anything ever since I deleted my LinkedIn account 4 years ago

aaladdin
Автор

Good job on the bait title :p.
I watched this just out of curiosity because I'm a huge proponent of structured logging.
You hit the nail on the head at every point, but I actually was not aware that composed strings are impermanent and repeatedly allocate, which really ratchets up the importance of doing this right!

RealTwiner
Автор

I was waiting for the standard Benchmark runs and reports, like you normally do. Including a version with the Log extension. 😞 🙂

tylerwilson
Автор

glad i planned to re-watch some of your videos on logging because i kept expecting you to show a benchmark that really pushed home the difference in memory allocation. But i'm sure you've already done that multiple times in talks and videos.

loop
Автор

Great advice! Use logging as its supposed to be used to receive all its benefits. Logging is not supposed to be overheat on your project, but use it badly and it will be.

I love using serilog, used to work with log4net before but now its almost always serilog.

BabyGhost
Автор

I love using Serilog with structured logs in a SQL Server table. However, there are so many people creating content on LinkedIn and elsewhere. It's really difficult to discern whose content is good. You see, Nick, there are many bad examples in the content of many developers. Thanks a lot for your LinkedIn Series.

saddamhossaindotnet
Автор

3:00 about multiple enumerations costing memory - isn't it generally the opposite? With ToList you're forcing all items to be stored temporarily, which prevents the enumeration being processed multiple times but at the expense of memory... unless the enumeration process itself is also storing everything?

TazG
Автор

I'd literally just been talking with one of my colleagues about your video on structured logging, and then I see you've published a new video about it!

sasukesarutobi
Автор

I hope you keep this series up because it is very beneficial.

Jimmy-hcit
Автор

I literally just took your dometrain logging course yesterday, so the title of this video made me laugh out loud. 😂😂

UnnDunn
Автор

Okay, source generated logging is going into by tool belt for sure. In some application, I wrote extension methods for ILogger, which just passed a fixed log message with custom parameters passed in. Wanted to avoid writing the same message multiple times. But it sounds like Source Generated Logs were what I should've done.

rGunti
Автор

My two cents if helps. Select, Where etc.. in linq are also called Deferred operators - as per multiple enumeration Nick said.
(opposite are Immediate operators i.e. ToList, ToArray, Count...)

Beacher
Автор

You know, "Content Cop" ain't wrong ;)

JustArion
Автор

I use Serilog and save the structured logs to a SQL Server table. The parameters are stored in an XML column. I never cared about performance that much for logging and so I always store every parameter, but I'm fairly sure in my particular scenario appending the parameter to the XML is more memory / CPU intensive than doing a simple string concatenation.
The final computed string gets stored in the table too (along with the template and the parameters), so Serilog does the concatenation anyway.

tedchirvasiu
Автор

It could be worth mentioning, that if your particular log level is not enabled it will skip processing of whatever was sent. In the linkedin example string has to be always allocated, regardless of whether it will be used later or not.

gieniapk
Автор

Omg, I had no idea the allocation optimization around using the templates! Where can I find out more about it, thankss

ahmedifhaam
Автор

The text says 6. episode but the creepy man in the video corner says 3. episode. Now I'm confused and crying

KeyboardKrieger