2

This question covers how to manually notice errors in NewRelic in Ruby.

I need to do the same thing in C#.

How can I manually send errors to NewRelic in .NET?

Community
  • 1
  • 1
Luke Willis
  • 8,429
  • 4
  • 46
  • 79

2 Answers2

6

According to NewRelic's .NET Api, you can do this with

NewRelic.Api.Agent.NewRelic.NoticeError(ex);

where ex is an Exception.

AncientToaster
  • 205
  • 1
  • 10
Luke Willis
  • 8,429
  • 4
  • 46
  • 79
  • should this be part of your original question or are you stating this as an answer that solves your initial question...? – MethodMan Sep 24 '14 at 20:39
  • @DJKRAZE I am [answering my own question](http://blog.stackoverflow.com/2011/07/its-ok-to-ask-and-answer-your-own-questions/) – Luke Willis Sep 24 '14 at 20:39
1

In order to do this across all WebApi as an ExceptionLogger to log errors into New Relic

Add the following class to your project

public class NewRelicExceptionLogger : ExceptionLogger
{
    public override void Log(ExceptionLoggerContext context)
    {
        NewRelic.Api.Agent.NewRelic.NoticeError(context.ExceptionContext.Exception);
    }
}

and register it Global.asax.cs under Application_Start():

protected void Application_Start()
{
    //...
    GlobalConfiguration.Configuration.Services.Add(typeof(IExceptionLogger), new NewRelicExceptionLogger());

}
Korayem
  • 12,108
  • 5
  • 69
  • 56