Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Issue #3: Refactoring ILogger #31

Closed
wants to merge 4 commits into from
Closed

Issue #3: Refactoring ILogger #31

wants to merge 4 commits into from

Conversation

sonjakhan
Copy link
Contributor

Moved extension method IsEnabled to the ILogger interface, renamed WriteCore to Write and changed the return type to void. This will break other repositories that use the ILogger interface, which I will update once I get feedback on the changes here.

@@ -37,19 +37,18 @@ public Logger(global::NLog.Logger logger)
Func<object, Exception, string> formatter)
{
var logLevel = GetLogLevel(eventType);
if (!_logger.IsEnabled(logLevel))
if (formatter != null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lodejard What does it mean if the formatter is null after this refactoring?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we ought to have a fallback? Like maybe call ToString on state (if it's not null), and then get some data from the exception, such as its Message and/or StackTrace?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or throw argument null exception? @Eilon's suggestion wouldn't be surprising either, but if the form a tter is null you're calling the wrong overload...

}
if (exception != null)
{
message += "\r\n" + exception;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Instead of \r\n use Environment.NewLine so that it'll work right on all OSes
  2. Should the newline be added only if there is a state and exception? Otherwise if there's only an exception then there'll be an empty line above it always, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on the formatting defined in NLog.config. In the sample it's

[level:logger] state
exception

so if there's no state it would be

[level:logger]
exception

I think it makes sense to have a new line before the exception even if there is no state, and I believe this code also has a new line even if there's no state. Does the CultureInfo make sure the \r\n is rendered correctly on all OSes?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CultureInfo doesn't affect newlines at all. It's more about the underlying OS (Windows, OS X, *nix, etc.).

I think I see your point about the newlines. So you always want the exception on its own line no matter what? I can live with that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would be most consistent with the extension methods. I will update the extension class to not hard code \r\n

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@victorhurdugaci Eilon and I discussed the new line here, do you still think the newline should be avoided if state == null?

using System.Diagnostics;
using Xunit;
#if ASPNET50
using Moq;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you using Moq at all? If not, remove the reference and enable the tests for ASPNET50

@pranavkm
Copy link
Contributor

pranavkm commented Oct 7, 2014

:shipit: when @Eilon is happy

@Eilon
Copy link
Member

Eilon commented Oct 7, 2014

I'm always happy. So I guess :shipit: 😄

@sonjakhan sonjakhan closed this Oct 14, 2014
@sonjakhan sonjakhan deleted the refactor-ilogger branch October 21, 2014 23:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants