2

I wonder why log4net provides the method

Info(object message, Exception e) 

(and of course Warn, Error etc.)

Why is the message parameter not a string? I'd guess that this way it is possible to pass any object and the log message is determined via ToString. But then again, why does the 'ususal' method

Info(string message)

uses a string and not an object as parameter?

3
  • Yeah, the question is not about the exception but about the log message.
    – anhoppe
    Mar 4, 2016 at 10:27
  • It does it because log4j does, and log4net is a port of that. You are also mistaken: the Info method takes an object as a parameter.
    – stuartd
    Mar 4, 2016 at 10:27
  • You are right, only the Format methods take a string. I fear the question is obsolete then.
    – anhoppe
    Mar 4, 2016 at 10:29

1 Answer 1

3

Log4Net offers IObjectRenderers which can turn an object in to a string format suitable for logging.

In the case of passing a string then it doesn't need to do anything, in the case of passing other objects it uses an IObjectRenderer.

If the method only took a string then it wouldn't be as flexible.

While there is an Info(object message) method, the ILog interface doesn't seem to expose an Info(string message) method so I'm not sure where you got that from?

1
  • You had a question, and now you know more about it. I don't think your question is invalid, it's just not the answer you were expecting!
    – user310988
    Mar 4, 2016 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.