What is the purpose of all the Logger overloads?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

What is the purpose of all the Logger overloads?

noopman
Hello!

I am qurious about all the overloads on the Logger class methods. What is the purpose of all of them?

When I look in the API documentation it appears as though the arguments are only parsed into the string message. But since string.Format() does not offer all of these overloads why does the NLog Logger? Is there some logic here that you can explain to me? Is there some perf gain somewhere that I cannot see?

See the example from your API documentation below!

Cheers,

M.

Example: Logger.Debug(string, int)
public void Debug(string message, int argument)
    Member of NLog.Logger

Summary:
Writes the diagnostic message at the Debug level using the specified System.Int32 as a parameter.

Parameters:
message: A string containing one format item.
argument: The System.Int32 argument to format.
Reply | Threaded
Open this post in threaded view
|

Re: What is the purpose of all the Logger overloads?

noopman
* BUMP *

Is there no dev on the team that can answer this?

I'd love to hear the reasoning for the BIG interface on NLog.Logger.

Cheers.

M.
Reply | Threaded
Open this post in threaded view
|

Re: What is the purpose of all the Logger overloads?

Jarek Kowalski
Administrator

The overloads are mainly for performance reason. This is to avoid boxing of common types of parameters if logging is disabled. Believe it or not, but it actually makes a lot of difference in a tight loop when logging is disabled.

In NLog 1.x there was a ton of overloads for each common parameter type but some were left out, in NLog 2.x I added a generic overload which handles all parameter types, but overloads from NLog 1.x had to stay because of backwards compatibility.

Let me know if this answers your question.

Jarek

NLog Blog
Reply | Threaded
Open this post in threaded view
|

Re: What is the purpose of all the Logger overloads?

noopman
Thank you for the answer Jarek. That makes a LOT of sense.

How big are the perf gains do you know?

M.