root / trunk / packages / Caliburn.Micro.Logging.1.5.0.0 / content / Caliburn / Micro / Logging / DebugLogger.cs @ 99882980
History | View | Annotate | Download (2.8 kB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Diagnostics; |
4 |
using System.Linq; |
5 |
using System.Text; |
6 |
|
7 |
// ReSharper disable CheckNamespace |
8 |
namespace Caliburn.Micro.Logging |
9 |
// ReSharper restore CheckNamespace |
10 |
{ |
11 |
/// <summary> |
12 |
/// Implementation of the ILog and ILogExtended interfaces using |
13 |
/// <see cref="Debug"/>. |
14 |
/// </summary> |
15 |
public class DebugLogger : ILog, ILogExtended |
16 |
{ |
17 |
#region Constants |
18 |
private const string ErrorText = "ERROR"; |
19 |
private const string WarnText = "WARN"; |
20 |
private const string InfoText = "INFO"; |
21 |
#endregion |
22 |
|
23 |
#region Fields |
24 |
private readonly Type _type; |
25 |
#endregion |
26 |
|
27 |
#region Constructors |
28 |
public DebugLogger(Type type) |
29 |
{ |
30 |
_type = type; |
31 |
} |
32 |
#endregion |
33 |
|
34 |
#region Helper Methods |
35 |
private string CreateLogMessage(string format, params object[] args) |
36 |
{ |
37 |
return string.Format("[{0}] {1}", DateTime.Now.ToString("o"), string.Format(format, args)); |
38 |
} |
39 |
#endregion |
40 |
|
41 |
#region ILog Members |
42 |
/// <summary> |
43 |
/// Logs the exception. |
44 |
/// </summary> |
45 |
/// <param name="exception">The exception.</param> |
46 |
public void Error(Exception exception) |
47 |
{ |
48 |
Debug.WriteLine(CreateLogMessage(exception.ToString()), ErrorText); |
49 |
} |
50 |
/// <summary> |
51 |
/// Logs the message as info. |
52 |
/// </summary> |
53 |
/// <param name="format">A formatted message.</param><param name="args">Parameters to be injected into the formatted message.</param> |
54 |
public void Info(string format, params object[] args) |
55 |
{ |
56 |
Debug.WriteLine(CreateLogMessage(format, args), InfoText); |
57 |
} |
58 |
/// <summary> |
59 |
/// Logs the message as a warning. |
60 |
/// </summary> |
61 |
/// <param name="format">A formatted message.</param><param name="args">Parameters to be injected into the formatted message.</param> |
62 |
public void Warn(string format, params object[] args) |
63 |
{ |
64 |
Debug.WriteLine(CreateLogMessage(format, args), WarnText); |
65 |
} |
66 |
#endregion |
67 |
|
68 |
#region Implementation of ILogExtended |
69 |
/// <summary> |
70 |
/// Logs the message as error. |
71 |
/// </summary> |
72 |
/// <param name="format">A formatted message.</param> |
73 |
/// <param name="args">Parameters to be injected into the formatted message.</param> |
74 |
public void Error(string format, params object[] args) |
75 |
{ |
76 |
Debug.WriteLine(CreateLogMessage(format, args), ErrorText); |
77 |
} |
78 |
/// <summary> |
79 |
/// Logs the exception. |
80 |
/// </summary> |
81 |
/// <param name="exception">The exception.</param> |
82 |
/// <param name="format">A formatted message.</param> |
83 |
/// <param name="args">Parameters to be injected into the formatted message.</param> |
84 |
public void Error(Exception exception, string format, params object[] args) |
85 |
{ |
86 |
Debug.WriteLine(CreateLogMessage(format + " - Exception = " + exception.ToString(), args), ErrorText); |
87 |
} |
88 |
#endregion |
89 |
} |
90 |
} |