Skip to content
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

Fix: exception is not correctly logged when calling without message #788

Merged
merged 3 commits into from Aug 7, 2015
Merged

Fix: exception is not correctly logged when calling without message #788

merged 3 commits into from Aug 7, 2015

Conversation

304NotModified
Copy link
Member

Added unit test for bug report: #787.

Without the message argument it's calling the generic version:

error(new Exception("test")

will call:

        public void Error<T>(T value)
        {
            if (this.IsErrorEnabled)
            {
                //LogLevel level, IFormatProvider formatProvider, T value
                this.WriteToTargets(LogLevel.Error, null, value);
            }
        }

This method is interpreting the argument as message. (which is correct). I'm not sure how to fix this neat - the Exception is (again) a special case.

This is not a bug since NLog 4, but we said that since NLog 4 the exception parameter is always the first one.

N.B.: creating a special method for Exception, like Error(Exception ex) won't solve it, as this works for Exeption but not for the sub classes of Exception - those will call the generic version.

Dunno how to solve this neat. Only thing that come to mind: re-introduce the is Exception quirk which just was removed in NLog 4 (another method).

Also what should be the result of Error(ex) when the ${message} layout renderer is used?

@304NotModified 304NotModified added this to the 4.1 milestone Jul 18, 2015
304NotModified added a commit that referenced this pull request Aug 7, 2015
…e-texts

Fix:  exception is not correctly logged when calling without message [WIP]
@304NotModified 304NotModified merged commit 3b6a55f into NLog:master Aug 7, 2015
@304NotModified 304NotModified changed the title Fix: exception is not correctly logged when calling without message [WIP] Fix: exception is not correctly logged when calling without message Aug 7, 2015
@304NotModified
Copy link
Member Author

Leave the PR like this. it fixed it and improvements can be done in future versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug report / Bug fix must have
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant