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

Commit

Permalink
incorporated feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
sonjakhan committed Oct 7, 2014
1 parent 44c6278 commit fcbcda7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/Microsoft.Framework.Logging.NLog/NLogLoggerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public void Write(
}
if (exception != null)
{
message += "\r\n" + exception;
message += Environment.NewLine + exception;
}
}
if (message != String.Empty)
if (!String.IsNullOrEmpty(message))

This comment has been minimized.

Copy link
@davidfowl

davidfowl Oct 7, 2014

Member

lowercase s

{
var eventInfo = LogEventInfo.Create(logLevel, _logger.Name, message, exception);
eventInfo.Properties["EventId"] = eventId;
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Framework.Logging/DiagnosticsLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public void Write(TraceType traceType, int eventId, object state, Exception exce
}
if (exception != null)
{
message += "\r\n" + exception;
message += Environment.NewLine + exception;
}
}
if (message != String.Empty)
if (!String.IsNullOrEmpty(message))
{
_traceSource.TraceEvent(eventType, eventId, message);
}
Expand Down
13 changes: 2 additions & 11 deletions src/Microsoft.Framework.Logging/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,15 @@ public Logger(LoggerFactory loggerFactory, string name)

public void Write(TraceType eventType, int eventId, object state, Exception exception, Func<object, Exception, string> formatter)
{
var count = _loggers.Length;
for (var index = 0; index != count; index++)
for (var index = 0; index < _loggers.Length; index++)
{
_loggers[index].Write(eventType, eventId, state, exception, formatter);
}
}

public bool IsEnabled(TraceType eventType)
{
var count = _loggers.Length;
for (var index = 0; index != count; index++)
{
if (_loggers[index].IsEnabled(eventType))
{
return true;
}
}
return false;
return _loggers.Any(l => l.IsEnabled(eventType));
}

public IDisposable BeginScope(object state)
Expand Down
3 changes: 2 additions & 1 deletion src/Microsoft.Framework.Logging/LoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ namespace Microsoft.Framework.Logging
public static class LoggerExtensions
{
private static readonly Func<object, Exception, string> TheMessage = (message, error) => (string)message;
private static readonly Func<object, Exception, string> TheMessageAndError = (message, error) => string.Format(CultureInfo.CurrentCulture, "{0}\r\n{1}", message, error);
private static readonly Func<object, Exception, string> TheMessageAndError = (message, error)
=> string.Format(CultureInfo.CurrentCulture, "{0}{1}{2}", message, Environment.NewLine, error);

/// <summary>
/// Writes a verbose log message.
Expand Down
20 changes: 10 additions & 10 deletions test/Microsoft.Framework.Logging.Test/DiagnosticsLoggerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ public class DiagnosticsLoggerTest
[Fact]
public static void IsEnabledReturnsCorrectValue()
{
SourceSwitch testSwitch = new SourceSwitch("TestSwitch", "Level will be set to warning for this test");
var testSwitch = new SourceSwitch("TestSwitch", "Level will be set to warning for this test");
testSwitch.Level = SourceLevels.Warning;

var factory = new LoggerFactory();
ILogger logger = factory.Create("Test");
var logger = factory.Create("Test");

factory.AddProvider(new DiagnosticsLoggerProvider(testSwitch, new ConsoleTraceListener()));

Assert.Equal(true, logger.IsEnabled(TraceType.Critical));
Assert.Equal(true, logger.IsEnabled(TraceType.Error));
Assert.Equal(true, logger.IsEnabled(TraceType.Warning));
Assert.Equal(false, logger.IsEnabled(TraceType.Information));
Assert.Equal(false, logger.IsEnabled(TraceType.Verbose));
Assert.True(logger.IsEnabled(TraceType.Critical));
Assert.True(logger.IsEnabled(TraceType.Error));
Assert.True(logger.IsEnabled(TraceType.Warning));
Assert.False(logger.IsEnabled(TraceType.Information));
Assert.False(logger.IsEnabled(TraceType.Verbose));
}

[Theory]
Expand All @@ -38,14 +38,14 @@ public static void IsEnabledReturnsCorrectValue()
[InlineData(SourceLevels.Warning, SourceLevels.Warning, false)]
public static void MultipleLoggers_IsEnabledReturnsCorrectValue(SourceLevels first, SourceLevels second, bool expected)
{
SourceSwitch firstSwitch = new SourceSwitch("FirstSwitch", "First Test Switch");
var firstSwitch = new SourceSwitch("FirstSwitch", "First Test Switch");
firstSwitch.Level = first;

SourceSwitch secondSwitch = new SourceSwitch("SecondSwitch", "Second Test Switch");
var secondSwitch = new SourceSwitch("SecondSwitch", "Second Test Switch");
secondSwitch.Level = second;

var factory = new LoggerFactory();
ILogger logger = factory.Create("Test");
var logger = factory.Create("Test");

factory.AddProvider(new DiagnosticsLoggerProvider(firstSwitch, new ConsoleTraceListener()));
factory.AddProvider(new DiagnosticsLoggerProvider(secondSwitch, new ConsoleTraceListener()));
Expand Down

0 comments on commit fcbcda7

Please sign in to comment.