Skip to content

Commit caefef7

Browse files
committed
Merge pull request #17 from AkosLukacs/master
In IIS integrated mode Elmah fails at application start (Can't access HttpContext.Current.Request)
2 parents 4461970 + 3a99d50 commit caefef7

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

src/.nuget/NuGet.exe

132 KB
Binary file not shown.

src/ServiceStack.Logging.Elmah/ElmahInterceptingLogger.cs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,37 +43,67 @@ public void DebugFormat(string format, params object[] args)
4343

4444
public void Error(object message, Exception exception)
4545
{
46-
ErrorLog.GetDefault(HttpContext.Current).Log(new Error(exception, HttpContext.Current));
46+
try {
47+
ErrorLog.GetDefault(HttpContext.Current).Log(new Error(exception, HttpContext.Current));
48+
}
49+
catch {
50+
ErrorLog.GetDefault(null).Log(new Error(exception));
51+
}
4752
log.Error(message, exception);
4853
}
4954

5055
public void Error(object message)
5156
{
52-
ErrorLog.GetDefault(HttpContext.Current).Log(new Error(new System.ApplicationException(message.ToString()), HttpContext.Current));
57+
try {
58+
ErrorLog.GetDefault(HttpContext.Current).Log(new Error(new System.ApplicationException(message.ToString()), HttpContext.Current));
59+
}
60+
catch {
61+
ErrorLog.GetDefault(null).Log(new Error(new System.ApplicationException(message.ToString())));
62+
}
5363
log.Error(message);
5464
}
5565

5666
public void ErrorFormat(string format, params object[] args)
5767
{
58-
ErrorLog.GetDefault(HttpContext.Current).Log(new Error(new System.ApplicationException(string.Format(format, args)), HttpContext.Current));
68+
try {
69+
ErrorLog.GetDefault(HttpContext.Current).Log(new Error(new System.ApplicationException(string.Format(format, args)), HttpContext.Current));
70+
}
71+
catch {
72+
ErrorLog.GetDefault(null).Log(new Error(new System.ApplicationException(string.Format(format, args))));
73+
}
5974
log.ErrorFormat(format, args);
6075
}
6176

6277
public void Fatal(object message, Exception exception)
6378
{
64-
ErrorLog.GetDefault(HttpContext.Current).Log(new Error(exception, HttpContext.Current));
79+
try {
80+
ErrorLog.GetDefault(HttpContext.Current).Log(new Error(exception, HttpContext.Current));
81+
}
82+
catch {
83+
ErrorLog.GetDefault(null).Log(new Error(exception));
84+
}
6585
log.Fatal(message, exception);
6686
}
6787

6888
public void Fatal(object message)
6989
{
70-
ErrorLog.GetDefault(HttpContext.Current).Log(new Error(new System.ApplicationException(message.ToString()), HttpContext.Current));
90+
try {
91+
ErrorLog.GetDefault(HttpContext.Current).Log(new Error(new System.ApplicationException(message.ToString()), HttpContext.Current));
92+
}
93+
catch {
94+
ErrorLog.GetDefault(null).Log(new Error(new System.ApplicationException(message.ToString())));
95+
}
7196
log.Fatal(message);
7297
}
7398

7499
public void FatalFormat(string format, params object[] args)
75100
{
76-
ErrorLog.GetDefault(HttpContext.Current).Log(new Error(new System.ApplicationException(string.Format(format, args)), HttpContext.Current));
101+
try {
102+
ErrorLog.GetDefault(HttpContext.Current).Log(new Error(new System.ApplicationException(string.Format(format, args)), HttpContext.Current));
103+
}
104+
catch {
105+
ErrorLog.GetDefault(null).Log(new Error(new System.ApplicationException(string.Format(format, args))));
106+
}
77107
log.FatalFormat(format, args);
78108
}
79109

0 commit comments

Comments
 (0)