Elmah add message to error logged through call to Raise(e)

后端 未结 2 1991
天命终不由人
天命终不由人 2021-02-07 22:11

I\'m a bit confused at how to add a message to an error logged programatically with ELMAH.

eg:

public ActionResult DoSomething(int id)
{
    try { ... }
         


        
2条回答
  •  悲哀的现实
    2021-02-07 22:40

    You can throw a new Exception setting the original as the inner exception and ELMAH will log the messages for both:

    catch(Exception e)
    {
        Exception ex = new Exception("ID = 1", e);
        ErrorSignal.FromCurrentContext().Raise(ex);
    }
    

    will show

    System.Exception: ID = 1 ---> System.NullReferenceException: Object reference not set to an instance of an object.
    

提交回复
热议问题