High-performance logging in .NET, the proper way

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

Hello everybody I'm Nick and in this video I will show how you can do high-performance logging in .NET. Logging is something that can be abused very easily but thankfully the latest versions of .NET have added a couple of ways to perform logging that is as efficient as possible.

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

Social Media:

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

Found your channel when i was looking into clean architecture and have been hooked ever since. Thanks for helping make us all better developers

calvinwilson
Автор

Thanks for sharing your knowledge with the community, Nick. Awesome videos. Purchased your bundle just to support what you do on YouTube. Please keep it up

anikitin
Автор

Brilliant timing, I was just working on adding extra logging to a service at work :D Cheers!

inzyster
Автор

Awesome video I just implemented this in a new projcet we are building at work and it really had a large impact!

AlyxSharkBite-
Автор

Serilog also provides an async sink to offload the logging on a separate thread.

asljahfaklsf
Автор

Thank you! I couldn't understand why VS began to throw errors at me. I tried to read the link, and actually managed to implement this Logger Definition in a static class and use it, but didn't fully understand why. I do now. Excellent explanation, thanks so much

diligencehumility
Автор

Back in the old days, I learned to do logging with the Debug class. The advantage I was told about was that any line made with that would simply not be there in the Release version. Althought this doesn't allow me to turn on debug logging in a Release environment, and I only have 2 levels, it is by far the most efficient way to get rid of debug logging in an Release environment.
I like knowing my relics.

frankroos
Автор

If performance of logging is important log messages should go to FIFO queue first and then picked up by background thread. That introduces small delay in reporting messages to the file but guarantees clients won't be affected by slowness of logging subsystem. And I will just say this: memory is cheap.

hensonk
Автор

You're a legend!! Such great videos

basschimmel
Автор

Nice video, it's surprising that something simple as logging is taken as-is without necessarily taking into consideration this kind of thing.

davilinkicefire
Автор

I did not know about that source gen method.

That is brilliant.
It removes a lot of the "cumbersomness" for creating the logger extensions.

JonathanPeel
Автор

nunca desista do seu canal vc tem potencial

vass_oura
Автор

Didn't think I could be surprised by a video about logging, but there you are

wojciechwilimowski
Автор

Would be great if you could dive into custom serialization and deserialization.

muhamedkarajic
Автор

Thanks Nick! Can you also give some insights on how to best optimise on the logger calls that writes to file, as the I/O calls normally slows down the code.

Mr
Автор

I wanted to "abuse" the logger for (thread safe) writing data to a log-file. I was VERY! surprised to see that .NET Core does NOT support writing to log-files out of the box.

lollo
Автор

Hey nick, your videos are great..! In one of your videos you showed how to inject a class that inherits an interface and also same interface is injected in constructor.
I have a similar situation. Can you help me find that video. It would be great 👍. Thanks..!

neeleshbodgal
Автор

adorei muitobom adoro seus videos sao especiais
abs

vass_oura
Автор

I like how you pretty much reached performance perfection here, but the amount of trade offs make me think I could only use this in cases where I have already written and can easily find the exact log function that I need. I would think that any situation where performance would be important enough to necessitate writing a new log function is probably a place where the log would grow way too large to be useful anyways. Most of all, I really just want to be able to use all the bells and whistles of string interpolation. What are your thoughts on the performance improvements of C#10 string interpolation? (My replies keep getting deleted, not sure if it is some sort of problem with YouTube or some other issue... you can handle the string interpolation yourself which allows you to structure your data however you like. This can be done with FormattableString or InterpolatedStringHandler, which also opens the door for similar performance optimizations to the ones in your video.)

rickvelde
Автор

It's a shame that NLog doesn't work particularly well with the past two videos you've created. The "callsite" ends up being the extension method name in the log file, so everything looks like it's coming from the same code. I'm using NLog with DI, and as a result I am still working with ILogger but I can't quite seem to keep the original callsite from extension methods.

Rakshasa