❔ ✅ Singleton, thread-safe logger with absolutely 0 runtime performance penalty when turned off
I've got an application that lazily discovers its state-space, as it needs it. Carrying through a logger object these state objects seems way too extensive (hence some singleton would be ideal instead of DI), as I'd only like to look at a few isolated cases, I really don't need logging all the time. When I do want to look at a run, I don't mind the performance-penalty, but I can't allow even an empty vcall wasted when I turn it off (99.9% of the time). Are there existing solutions for weird cases like this?
15 Replies
Ah also I'm totally fine with turning off the logger at build-time, but I'd like to avoid tying it to a macro at invocation-site each time like
there's an ifdef attribute that removes the call as well
i forgot what it was called
its what the Debug class uses
I think Nick Chapsas did a video on it the other day
Oh the
[Conditional("...")]
you mean?ye
Thanks, that's a really good idea
Ah lol I even have that in the project, why didn't I think of it
Thanks anyway guys
!close
Closed!
i must have missed that, if u find the vid again mind linking it to me?
I can't find it, title must've been clickbait so you can't use "Condition attribute". It was a video by a microsoft employee
awh
Hassan Habib
YouTube
Enabling/Disabling Routines in C#
In this session, I'm going to walk you through a quick demo of leveraging [Conditional] capability in C# to enable and disable blocks of code in your program seamlessly and natively.
Read more about Conditional here:
https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.conditionalattribute?view=net-7.0
Here's the code I used for thi...
terrible SEO haha
wow, i learnt something new today, [Conditional()] and #undef
I've actually watched vids from that youtuber a few times now, figured i'd drop a sub now, small world though, the man only has around 12k subs
I love Nick's work too
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.