Need help with raven-csharp?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

getsentry
231 Stars 133 Forks BSD 3-Clause "New" or "Revised" License 1K Commits 3 Opened issues

Description

Superseded by: https://github.com/getsentry/sentry-dotnet

Services available

!
?

Need anything else?

Contributors list


Note

Sentry is unifying the API across all SDKs. With that, a new .NET SDK was created.

This SDK is still recommended for .NET Framework 3.5 to 4.6.0.

For .NET Framework 4.6.1, .NET Core 2.0, Mono 5.4 or higher please use the new SDK.

Raven is the official legacy .NET client for Sentry

| | Stable | Pre-release | | -------------------: | :----------------------------: | :------------------: | | GitHub | GitHub release | - | | SharpRaven | NuGet | NuGet | | SharpRaven.Nancy | NuGet | NuGet | | Travis Build | Master | Develop | | AppVeyor Build | Master | Develop |

Usage

Instantiate the client with your 'Data Source Name' (DSN):

var ravenClient = new RavenClient("https://[email protected]/project-id");

Capturing Exceptions

Call out to the client in your catch block:

try
{
    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:

try
{
    // ...    
}
catch (Exception exception)
{
    exception.Data.Add("SomeKey", "SomeValue");
    throw;
}

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 or later build of SharpRaven, there's an

async
version of the
Capture
method as well:
async Task 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("https://[email protected]/project-id"));
}

or through configuration:

  
    

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;
};

Get it!

You can clone and build SharpRaven yourself, but for those of us who are happy with prebuilt binaries, there's NuGet packages of both SharpRaven and SharpRaven.Nancy.

Resources

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.