0

Entity Framework's DbEntityValidationException renders a message of

Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.

With a stack pointing to where the error occurred. It would be really, really useful if we could dig into the collection of errors, and write out the property and error message. Is there any way in Elmah where we can customize the output for this exception type only?

Brian Mains
  • 50,520
  • 35
  • 148
  • 257

1 Answers1

0

ELMAH only logs information about an error from the shared stuff on various exception. If the exception message or stacktrace doesnt contain the 'EntityValidationErrors' details, you need to save those yourself.

You can create a filter in ELMAH, implemented to check the type of the exception. If the type is DbEntityValidationException, you can dismiss that exception and raise a new one, containing a ToString of each item in the EntityValidationErrors property as the error detail.

Community
  • 1
  • 1
ThomasArdal
  • 4,999
  • 4
  • 33
  • 73