Skip to content

Commit a85030f

Browse files
committed
Merge pull request #5 from Arxisos/master
Improved elmah logger
2 parents c7debad + 81eb227 commit a85030f

1 file changed

Lines changed: 26 additions & 41 deletions

File tree

src/ServiceStack.Logging.Elmah/ElmahInterceptingLogger.cs

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,10 @@ namespace ServiceStack.Logging.Elmah
66
{
77
/// <summary> Writes Elmah intercepting logger. </summary>
88
/// <remarks> 9/2/2011. </remarks>
9-
public class ElmahInterceptingLogger
9+
public class ElmahInterceptingLogger
1010
: ILog
1111
{
12-
private readonly ILog _log;
13-
private readonly ErrorLog _errorLog;
14-
15-
/// <summary> Constructor. </summary>
16-
/// <remarks>
17-
/// Logs to Elmahs ErrorLog.GetDefault. Only Error and Fatal are passed along to Elmah, while all other errors will be written to the
18-
/// wrapped logger.
19-
/// </remarks>
20-
/// <param name="log"> The underlying log to write to. </param>
21-
///
22-
/// <exception cref="ArgumentNullException"> Thrown when the wrapped log is null. </exception>
23-
public ElmahInterceptingLogger(ILog log)
24-
: this(log, ErrorLog.GetDefault(HttpContext.Current))
25-
{ }
12+
private readonly ILog log;
2613

2714
/// <summary> Constructor. </summary>
2815
/// <remarks>
@@ -32,99 +19,97 @@ public ElmahInterceptingLogger(ILog log)
3219
/// <exception cref="ArgumentNullException"> Thrown when either the wrapped ILog or Elmah ErrorLog are null. </exception>
3320
/// <param name="log"> The underlying log to write to. </param>
3421
/// <param name="errorLog"> The error log. </param>
35-
public ElmahInterceptingLogger(ILog log, ErrorLog errorLog)
22+
public ElmahInterceptingLogger(ILog log)
3623
{
3724
if (null == log) { throw new ArgumentNullException("log"); }
38-
if (null == errorLog) { throw new ArgumentNullException("errorLog"); }
3925

40-
_log = log;
41-
_errorLog = errorLog;
26+
this.log = log;
4227
}
4328

4429
public void Debug(object message, Exception exception)
4530
{
46-
_log.Debug(message, exception);
31+
log.Debug(message, exception);
4732
}
4833

4934
public void Debug(object message)
5035
{
51-
_log.Debug(message);
36+
log.Debug(message);
5237
}
5338

5439
public void DebugFormat(string format, params object[] args)
5540
{
56-
_log.DebugFormat(format, args);
41+
log.DebugFormat(format, args);
5742
}
5843

5944
public void Error(object message, Exception exception)
6045
{
61-
_errorLog.Log(new Error(exception, HttpContext.Current));
62-
_log.Error(message, exception);
46+
ErrorLog.GetDefault(HttpContext.Current).Log(new Error(exception, HttpContext.Current));
47+
log.Error(message, exception);
6348
}
6449

6550
public void Error(object message)
6651
{
67-
_errorLog.Log(new Error(new System.ApplicationException(message.ToString()), HttpContext.Current));
68-
_log.Error(message);
52+
ErrorLog.GetDefault(HttpContext.Current).Log(new Error(new System.ApplicationException(message.ToString()), HttpContext.Current));
53+
log.Error(message);
6954
}
7055

7156
public void ErrorFormat(string format, params object[] args)
7257
{
73-
_errorLog.Log(new Error(new System.ApplicationException(string.Format(format, args)), HttpContext.Current));
74-
_log.ErrorFormat(format, args);
58+
ErrorLog.GetDefault(HttpContext.Current).Log(new Error(new System.ApplicationException(string.Format(format, args)), HttpContext.Current));
59+
log.ErrorFormat(format, args);
7560
}
7661

7762
public void Fatal(object message, Exception exception)
7863
{
79-
_errorLog.Log(new Error(exception, HttpContext.Current));
80-
_log.Fatal(message, exception);
64+
ErrorLog.GetDefault(HttpContext.Current).Log(new Error(exception, HttpContext.Current));
65+
log.Fatal(message, exception);
8166
}
8267

8368
public void Fatal(object message)
8469
{
85-
_errorLog.Log(new Error(new System.ApplicationException(message.ToString()), HttpContext.Current));
86-
_log.Fatal(message);
70+
ErrorLog.GetDefault(HttpContext.Current).Log(new Error(new System.ApplicationException(message.ToString()), HttpContext.Current));
71+
log.Fatal(message);
8772
}
8873

8974
public void FatalFormat(string format, params object[] args)
9075
{
91-
_errorLog.Log(new Error(new System.ApplicationException(string.Format(format, args)), HttpContext.Current));
92-
_log.FatalFormat(format, args);
76+
ErrorLog.GetDefault(HttpContext.Current).Log(new Error(new System.ApplicationException(string.Format(format, args)), HttpContext.Current));
77+
log.FatalFormat(format, args);
9378
}
9479

9580
public void Info(object message, Exception exception)
9681
{
97-
_log.Info(message, exception);
82+
log.Info(message, exception);
9883
}
9984

10085
public void Info(object message)
10186
{
102-
_log.Info(message);
87+
log.Info(message);
10388
}
10489

10590
public void InfoFormat(string format, params object[] args)
10691
{
107-
_log.InfoFormat(format, args);
92+
log.InfoFormat(format, args);
10893
}
10994

11095
public bool IsDebugEnabled
11196
{
112-
get { return _log.IsDebugEnabled; }
97+
get { return log.IsDebugEnabled; }
11398
}
11499

115100
public void Warn(object message, Exception exception)
116101
{
117-
_log.Warn(message, exception);
102+
log.Warn(message, exception);
118103
}
119104

120105
public void Warn(object message)
121106
{
122-
_log.Warn(message);
107+
log.Warn(message);
123108
}
124109

125110
public void WarnFormat(string format, params object[] args)
126111
{
127-
_log.WarnFormat(format, args);
112+
log.WarnFormat(format, args);
128113
}
129114
}
130115
}

0 commit comments

Comments
 (0)