Pergunta

Estou um pouco confuso sobre como adicionar uma mensagem a um erro registrado programaticamente com o Elmah.

por exemplo:

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 que tudo o que Elmah pode fazer é registrar a exceção bruta, como também posso registrar minhas próprias informações de depuração?

Foi útil?

Solução

Você pode lançar uma nova exceção definindo o original como a exceção interna e Elmah registrará as mensagens 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.

Outras dicas

Eu descobri que também posso fazer algo como:

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

Para registrar minhas próprias mensagens. Então, quando eu navego para

http://localhost:5050/elmah.axd

Eu vejo minhas mensagens como tipo notimplementException. Não é muito bonito, mas funciona.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top