0

I'm working out an implementation of ELMAH in a web application that logs exceptions to a SQL Server. That's inconsequential, however. My goal is to include the application name in the log so I can easily identify the offending application at a glance when checking error reports. I've searched far and wide spending hours trying to find a solution. I've included Application Name=[myApp] in my SQL Server connection string, but that only helps me to identify the app during a SQL Server trace and not in my actual error logging.

Has anyone done this? Here is an example of a log record in my database. I would like to see the Application Name listed as well. This happens to be the ELMAH implementation of the table, but it could just as well have been a custom table with the same field.

enter image description here

I would think this should be as simple as adding a value to the web.config or something, but I can't seem to find any solution like that or any other. I should probably also note that I'm using IIS 7.5 and .NET 4.0 in case that has anything to do with it. :)

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Chiramisu
  • 4,687
  • 7
  • 47
  • 77

2 Answers2

0

Perhaps the responses to this question will help...

PS. Don't look at the accepted answer but the follow up where the <errorLog> element example is given...

Community
  • 1
  • 1
nkvu
  • 5,551
  • 2
  • 16
  • 12
  • I can't seem to figure out where that tag goes. So far, still no luck. :( – Chiramisu Apr 01 '13 at 01:22
  • [This](https://code.google.com/p/elmah/wiki/Oracle) example is for Oracle but the principle is the same (scroll through the comments to see an example)...Also, if you post up your config file (including the ELMAH elements) then perhaps someone could have a look at that? – nkvu Apr 01 '13 at 03:56
  • Also, here's the [sample](http://elmah.googlecode.com/svn/tags/REL-1.2/samples/web.config) ELMAH web.config - the example in my previous comment references it but I think it links to the wrong one (doesn't have all the detail bits in there) – nkvu Apr 01 '13 at 04:04
  • I've tried your suggestions and seem to be running into a .NET 4 issue? Downgrading the target version is not an acceptable solution, so I'm not sure what else to try at this point. – Chiramisu Apr 01 '13 at 04:32
  • Would it be possible (if you are comfortable with it) to post your entire web.config? We've used ELMAH in some of our .NET 4.0 web apps and have not encountered issues previously – nkvu Apr 01 '13 at 04:38
0

As it is my practice to always fill out the assembly info for all my applications, I have elected to populate this field from My.Application.Info.Title which I just figured out how to access programmatically. To set this field in ELMAH, I set the ApplicationName value of my SqlErrorLog object like so:

Dim se As New Elmah.SqlErrorLog(ConnectionStrings("Elmah").ConnectionString)
se.ApplicationName = My.Application.Info.Title

The assembly info can be set by opening the project properties -> Application tab -> click Assembly Information... -> set "Title" value.

Now when you call the Log function for this object, it will create a database entry including the Application Name.

Chiramisu
  • 4,687
  • 7
  • 47
  • 77