Zwei James
Zwei James

Reputation: 73

NLog: logger.Error(string, Exception, param objects[] args) function doesn't log my exception

I'm having a problem logging my exceptions using this piece of code:

Logger.logger.Error("Exception occured", ex, "");

because it only logs the message but when I use the same function with 2 arguments supplied in it then it will work, though it is obsolete that's why I'm reluctant in using it.

This is the piece of code that is working and i'm currently using:

Logger.logger.Error("Exception occured", ex);

Any help would be appreciated. Thanks!

Upvotes: 2

Views: 2564

Answers (2)

svoychik
svoychik

Reputation: 1327

seems like you mistook parameters order. An exception should be first, second is a message

From NLog sources

public void Error(Exception exception, [Localizable(false)] string message)

public void Error(Exception exception, [Localizable(false)] string message, params object[] args)

Upvotes: 2

kara
kara

Reputation: 3455

NLog changed the functions.

In some older Version you had:

_logger.ErrorException("My Message", myException);

Now the first param ist of Type Exception:

_logger.Error(myException, "My Message: {0}", myException.Message);

..ErrorException() is now obsolete..

Upvotes: 1

Related Questions