-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Internal logger calls impact when it is disabled #56
Comments
Is this NLog's internal logger? Are there performance issues? |
I would like to try adding extension methods accepting a lambda so that string concatenation and possibly other statements only get executed when the logger is enabled. |
Recent NLog releases have But the most efficient is to first check |
I agree with @luigiberrettini, having a wrapper that handles the level enabled detection and only invokes the supplied action as necessary would be great. Perhaps this could get rolled back into NLog itself? |
sounds good to me. That was also the reason to react here ;) |
Thanks @304NotModified, I'll look at raising a ticket on the main NLog project as well (if one doesn't already exist) and if I get time do a branch for Targets.Syslog. Out of interest (and I haven't yet looked at the NLog backlog), do you know of any plans to roll this type of functionality into the NLog:ILogger interface etc? SLF4J has this type of interface and it is rather useful ;-) Cheers, Jon. |
not for NLog 4 as that will be a breaking change. |
If @JonPaz is going to create a PR for NLog I will then upgrade the NLog dependency in this target. |
because customers could have written their own logger class which implements But to be clear, do you like to add this to |
It is needed for the InternalLogger but I honestly don't know if the InternalLogger implements ILogger or is a standalone class with its own behavior. |
It doesn't as ILogger contains a lot of methods and InternalLogger is a static class |
anyway PR accepted, unit tests are mandatory ;) |
@JonPaz IMHO you only have to overload the Log and Write functions with wrappers that accept a lambda and in their body call it and pass the resulting string to the currently implemented versions of those methods. |
@304NotModified - I wouldn't miss those out! |
created a PR already (NLog/NLog#1919), as I will try to release 4.4.2 soon |
Great stuff @304NotModified , you're faster than I am ;-) |
@luigiberrettini - Just a quick message to say that we're now using this target in our production system and it is working nicely, thanks for all of your hard work!!! I'll have a look at getting it running with .Net core at some point in the next few weeks. |
* Handle non-ThreadAgnostic layouts (luigiberrettini#79 closes luigiberrettini#75) * Fix entry assembly fallback detection (luigiberrettini#80 closes luigiberrettini#76) * Decrease internal logger calls performance hit (luigiberrettini#81 closes luigiberrettini#56) By using InternalLogger lambda parameters, strings will be built only if the lambda is called i.e. only if that level of the internal logger is enabled * Fix: use RFC 5424 config values instead of hardcoded ones
@luigiberrettini I guess the lambda allocation is faster than the string-format, but an even faster alternative is:
Then there is no allocations at all. |
@snakefoot it allocates a string? ;) |
@304NotModified Yes :) but it is a one time interned string-allocation, so it is a one time penalty, while the lambda-capture-local-context-allocation is for every log-event. |
You're right @snakefoot, But I have my doubts if that has any impact in performance in practice (the lambda) |
The lambda allocations has a cost, and will put a strain on the GC0-collections, but yes they are cheaper than performing a string.Format(). I was just referring to the PR-title "Internal logger calls should not impact when it is not enabled". And my suggestion would lower the impact even further, so it just becomes a stack-allocation. |
Yes that's true! |
If that formatting signature is already available I will give it a try, thanks @snakefoot! |
Provide a way to disable internal logger calls and message creation when the internal logger / that level of internal logging is disabled.
The text was updated successfully, but these errors were encountered: