The Biggest Lie About the .NET Logger | .NET Tips 7

preview_player
Показать описание
The .NET Logging API is lying!
Рекомендации по теме
Комментарии
Автор

I always wondered why the params was there and ignored it because it didn't print the object to log. Now I know how to use it. Thanks!

lorddraagon
Автор

Finally a tip I actually already knew the answer to in advance 😂

clonger
Автор

I wouldn't have known this but the IDE started telling me to stop doing this a month ago or so

XZeroKPS
Автор

Note that when you use the other methods, you will always create the string before passing it to the logger. So all the .toString() calls are evaluated, even if you pass the string to Verbose/Trace or Debug, but only have the Info log level activated. That's why you should definitely prefer the lazy evaluation done by the logger, that checks the active log level before doing something.

ElCerdoBlanco
Автор

True. We have this issue with high memory usage. Fixing the logger with messagetemplate resolved. Observed significant impact of memory usage too ❤

jaswanthmca
Автор

Your logger still has to use memory to do the string interpolation when writing logs to a file. However, this method means you do not do the string interpolation for log lines that are disabled due to your currently configured logging level.

RealCheesyBread
Автор

I used the interprelated but when I checked the logs I didn't get the object name so since then I have been using the template one
Thanks for the deep explanation

khalednabilcs
Автор

Thank you for reminding me I need to log…

jeffreyepiscopo
Автор

Well …looks like I have a bunch of loggers I need to fix haha.

DoeJohn
Автор

Thanks for explaining why you should do it this way, since that is something many fail to do

allothernameswherealreadytaken
Автор

Thanks for this ! I think we might be using it wrong at my company as well ! I've shared this !

facundosoler
Автор

I use Logger for Displaying Exception Messages...can Also use Print Stack Trace or the Simple getString()

adityaranjansahoo
Автор

Oh that's what IntelliSense was suggesting all this time haha

Denmaverick
Автор

This is really important if you do a LOT of logging

Anequit
Автор

I'm used to using the TelemetryClient because it gives me more control than the ILogger when logging into Azure. I used to get warnings in my IDE that the message should not have dynamic parts (it's called "eventName" when you call TrackEvent, so it makes sense that it should be static). So I'm used to putting all the specific data in the custom dimensions, not in the main message (which is just something like "CustomerCreated", and no extra info). Maybe I'm doing it wrong, but it has served me well so far, and makes it easy to create alerting and dashboards.

zabustifu
Автор

serilogger has the signature Log.Information(string 👍

terjes
Автор

Sort of reminds me of Expression<Func<T>> vs Func<T>. Is there some language level feature which makes these string templates different from other strings, or do these Log methods simply have a manual implementation of the functionality? If it’s the latter, does the IDE simply have a hard-coded list of methods it knows use this functionality so it can provide the syntax highlighting of template params?

jacobstamm
Автор

Please make an indepth video also how u do filtering in your logging and so on can be also paid I don't mind

kknheyahsshshshd
Автор

Thx, good to know. We have created our own wrappers that use delegates in case there's a listener.

RusWatcher
Автор

Dotnet should fix this wrong naming immediately. Such a silly mistake.

nithinb
visit shbcf.ru