The C# SDK is maintained and supported by the Sentry community. Learn more about the project on GitHub.

Raven is the C# client for Sentry. Raven relies on the most popular logging libraries to capture and convert logs before sending details to a Sentry instance.


A NuGet Package is available for SharpRaven if you don’t want to compile it yourself.

Instantiate the client with your DSN:

var ravenClient = new RavenClient("___DSN___");

Capturing Exceptions

Call out to the client in your catch block:

    int i2 = 0;
    int i = 10 / i2;
catch (Exception exception)
    ravenClient.Capture(new SentryEvent(exception));

Logging Non-Exceptions

You can capture a message without being bound by an exception:

ravenClient.Capture(new SentryEvent("Hello World!"));

Additional Data

You can add additional data to the Exception.Data property on exceptions thrown about in your solution:

    // ...
catch (Exception exception)
    exception.Data.Add("SomeKey", "SomeValue");

The data SomeKey and SomeValue will be captured and presented in the extra property on Sentry.

Additionally, the SentryEvent class allow you to provide extra data to be sent with your request, such as ErrorLevel, Fingerprint, a custom Message and Tags.

Async Support

In the .NET 4.5 build of SharpRaven, there are async versions of the above methods as well:

async Task<string> CaptureAsync(SentryEvent @event);

Nancy Support

You can install the SharpRaven.Nancy package to capture the HTTP context in Nancy applications. It will auto-register on the IPipelines.OnError event, so all unhandled exceptions will be sent to Sentry.

The only thing you have to do is provide a DSN, either by registering an instance of the Dsn class in your container:

protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
    container.Register(new Dsn("http://public:secret@example.com/project-id"));

or through configuration:

    <section name="sharpRaven" type="SharpRaven.Nancy.NancyConfiguration, SharpRaven.Nancy" />
    <dsn value="http://public:secret@example.com/project-id" />

The DSN will be picked up by the auto-registered IRavenClient instance, so if you want to send events to Sentry, all you have to do is add a requirement on IRavenClient in your classes:

public class LoggingModule : NancyModule
    private readonly IRavenClient ravenClient;

    public LoggingModule(IRavenClient ravenClient)
        this.ravenClient = ravenClient;

Debugging SharpRaven

If an exception is raised internally to RavenClient it is logged to the Console. To extend this behaviour use the property ErrorOnCapture:

ravenClient.ErrorOnCapture = exception =>
    // Custom code here

You can also hook into the BeforeSend function to inspect or manipulate the data being sent to Sentry before it is sent:

ravenClient.BeforeSend = requester =>
    // Here you can log data from the requester
    // or replace it entirely if you want.
    return requester;