Change DebugLogger to TraceLogger, which logs even in Release builds

This commit is contained in:
Antony Male 2014-07-30 15:20:30 +01:00
parent 2f250355ee
commit bc9362eeee
4 changed files with 16 additions and 16 deletions

View File

@ -60,7 +60,7 @@ namespace Stylet.Logging
/// <summary>
/// ILogger implementation which uses Debug.WriteLine
/// </summary>
public class DebugLogger : ILogger
public class TraceLogger : ILogger
{
private readonly string name;
@ -68,7 +68,7 @@ namespace Stylet.Logging
/// Create a new DebugLogger with the given name
/// </summary>
/// <param name="name">Name of the DebugLogger</param>
public DebugLogger(string name)
public TraceLogger(string name)
{
this.name = name;
}
@ -80,7 +80,7 @@ namespace Stylet.Logging
/// <param name="args">format parameters</param>
public void Info(string format, params object[] args)
{
Debug.WriteLine(String.Format("[{1}] INFO {0}", String.Format(format, args), this.name), "Stylet");
Trace.WriteLine(String.Format("INFO [{1}] {0}", String.Format(format, args), this.name), "Stylet");
}
/// <summary>
@ -90,7 +90,7 @@ namespace Stylet.Logging
/// <param name="args">format parameters</param>
public void Warn(string format, params object[] args)
{
Debug.WriteLine(String.Format("[{1}] WARN {0}", String.Format(format, args), this.name), "Stylet");
Trace.WriteLine(String.Format("WARN [{1}] {0}", String.Format(format, args), this.name), "Stylet");
}
/// <summary>
@ -101,9 +101,9 @@ namespace Stylet.Logging
public void Error(Exception exception, string message = null)
{
if (message == null)
Debug.WriteLine(String.Format("[{1}] ERROR {0}", exception, this.name), "Stylet");
Trace.WriteLine(String.Format("ERROR [{1}] {0}", exception, this.name), "Stylet");
else
Debug.WriteLine(String.Format("[{2}] ERROR {0} {1}", message, exception, this.name), "Stylet");
Trace.WriteLine(String.Format("ERROR [{2}] {0} {1}", message, exception, this.name), "Stylet");
}
}
@ -129,7 +129,7 @@ namespace Stylet.Logging
/// <remarks>
/// e.g. LogManager.LoggerFactory = name => new MyLogger(name);
/// </remarks>
public static Func<string, ILogger> LoggerFactory = name => new DebugLogger(name);
public static Func<string, ILogger> LoggerFactory = name => new TraceLogger(name);
/// <summary>
/// Get a new ILogger for the given type

View File

@ -40,7 +40,7 @@ namespace StyletUnitTests
{
LogManager.Enabled = true;
var logger = LogManager.GetLogger("test");
Assert.IsInstanceOf<DebugLogger>(logger);
Assert.IsInstanceOf<TraceLogger>(logger);
}
[Test]

View File

@ -64,7 +64,7 @@
<Compile Include="ConductorOneActiveTests.cs" />
<Compile Include="ConductorTests.cs" />
<Compile Include="DebugConverterTests.cs" />
<Compile Include="DebugLoggerTests.cs" />
<Compile Include="TraceLoggerTests.cs" />
<Compile Include="EqualityConverterTests.cs" />
<Compile Include="EventActionTests.cs" />
<Compile Include="EventAggregatorTests.cs" />

View File

@ -11,7 +11,7 @@ using System.Threading.Tasks;
namespace StyletUnitTests
{
[TestFixture]
public class DebugLoggerTests
public class TraceLoggerTests
{
private class StringTraceListener : TraceListener
{
@ -34,14 +34,14 @@ namespace StyletUnitTests
public void SetUp()
{
this.listener = new StringTraceListener();
Debug.Listeners.Clear();
Debug.Listeners.Add(this.listener);
Trace.Listeners.Clear();
Trace.Listeners.Add(this.listener);
}
[Test]
public void InfoWritesAppropriateString()
{
var logger = new DebugLogger("testName");
var logger = new TraceLogger("testName");
logger.Info("{0} message", "test");
Assert.AreEqual(1, this.listener.messages.Count);
@ -56,7 +56,7 @@ namespace StyletUnitTests
[Test]
public void WarnWritesAppropriateString()
{
var logger = new DebugLogger("loggerName");
var logger = new TraceLogger("loggerName");
logger.Warn("this is a {0} message", "test");
Assert.AreEqual(1, this.listener.messages.Count);
@ -71,7 +71,7 @@ namespace StyletUnitTests
[Test]
public void ErrorWithMessageWritesAppropriateString()
{
var logger = new DebugLogger("loggerWithErrorName");
var logger = new TraceLogger("loggerWithErrorName");
var e = new Exception("exception message");
logger.Error(e, "accompanying message");
@ -88,7 +88,7 @@ namespace StyletUnitTests
[Test]
public void ErrorWithoutMessageWritesAppropriateString()
{
var logger = new DebugLogger("loggerWithErrorName");
var logger = new TraceLogger("loggerWithErrorName");
var e = new Exception("exception message");
logger.Error(e);