Elmah: Exception.Data dictionary NOT logged.
What steps will reproduce the problem?
- Log any exception with some data in
Exception.Datadictionary. - go to UI (elmah.axd)
- search through Details and XML.
What is the expected output? What do you see instead?
- get
Exception.Datalogged. It’s NOT logged.
Originally reported on Google Code with ID 162
Reported by Alexander.Chervony on 2010-03-17 18:38:21
About this issue
- Original URL
- State: open
- Created 9 years ago
- Reactions: 1
- Comments: 38 (31 by maintainers)
@arc95 In regards to the example found on docs.elmah.io, that is possible with elmah.io only. elmah.io and ELMAH are not the same thing. elmah.io were originally a remote error logger for ELMAH, but today a full error management system for all major .NET web and logging frameworks. I totally understand why you are confused by the naming. We are currently in the process of changing our name to something not related to ELMAH (the open source project which is awesome by the way 😄).
It mixes server variables with arbitrary custom data and if you’re happy to run with that then it’s your call.
Best to ask @boena about that.
Thanks, @atifaziz! Came across this possible solution: https://stackoverflow.com/a/22647084/177416. It uses the
error.ServerVariablescollection. What do you think?Also, where can I find this project (its link is broken)? https://github.com/boena/elmah-with-custom-data
@arc95 Your best bet is to customize the
SqlErrorLogvia derivation and make it aware of the data dictionary stored in anException. You would have to customize the SQL database objects to pass and log, as well as later retrieve, the additional information to and from an additional column. You would then override theLog,GetError&GetErrors(including async versions) methods ofSqlErrorLog. TheErrorobject passed to theLogmethod has a property calledExceptionusing which you can retrieve the exception from which the error was created and get at its data dictionary for logging. Retrieval is trickier because none of the built-in views and other infrastructure will be aware of the additional information. In fact, theErrorclass is sealed so how do you add and return any extra information? For that, you could leverageConditional​Weak​Table<,>to have one class supplement another. Take a look atLoggedExceptionfrom the ELMAH Bootstrapper project for an example of how to do this.maybe you could add a event
OnLogging(Error error)onErrorLogModulewhere the users can customize the error? This would make it possible for users to customize the error message, for example to log the Data dictionary and format it anyway they like. The event could look a like this;public Action<Error> OnLogging(Error error);a usage for of the event for logging the Data dictionary could be implemented: