Created
March 28, 2016 01:49
-
-
Save martinabrahams/a66906f2fccd3efd4ed3 to your computer and use it in GitHub Desktop.
Create a custom SQL error log for ELMAH. Append data stored in HttpContext.Items to log entries to provide critical debugging info.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Elmah; | |
using System; | |
using System.Collections; | |
using System.Text; | |
namespace MyProject | |
{ | |
public class ElmahCustomSqlErrorLog : SqlErrorLog | |
{ | |
public ElmahCustomSqlErrorLog(IDictionary config) : base(config) { } | |
public ElmahCustomSqlErrorLog(string connectionString) : base(connectionString) { } | |
public override string Log(Error error) | |
{ | |
if (error == null) | |
throw new ArgumentNullException("error"); | |
var webserviceLog = System.Web.HttpContext.Current.Items["CustomItem"] as StringBuilder; | |
if (webserviceLog != null) | |
{ | |
error.Detail += "\r\n\r\n-- Custom Entry Log --\r\n\r\n" + webserviceLog.ToString(); | |
} | |
return base.Log(error); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<configuration> | |
<elmah> | |
<errorLog type="ElmahCustomSqlErrorLog, MyProject" connectionStringName="DefaultConnection" applicationName="MyProject" /> | |
</elmah> | |
</configuration> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment