Pregunta

Estoy un poco confundido en cómo agregar un mensaje a un error registra mediante programación con ELMAH.

por ejemplo:

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

    catch (Exception e)
    {
        // I want to include the 'id' param value here, and maybe some
        // other stuff, but how?
        ErrorSignal.FromCurrentContext().Raise(e);
    }
}

Parece todo Elmah puede hacer es registrar la excepción prima, ¿cómo puedo entrar también mi propia información de depuración?

¿Fue útil?

Solución

Se puede lanzar una nueva configuración de la original como la excepción interna Excepción y ELMAH registrará los mensajes para ambos:

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

mostrará

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

Otros consejos

Me di cuenta de que también puedo hacer algo como:

Elmah.ErrorSignal.FromCurrentContext().Raise(new NotImplementedException("class      FbCallback.Page_Load() Request.Url= " + Request.Url));

Para registrar mis propios mensajes. A continuación, cuando hojeo a

http://localhost:5050/elmah.axd

Veo mi mensajes como el tipo NotImplementedException. No es muy bonita, pero funciona.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top