# Legacy SDK | Sentry for Xamarin

##### Deprecation Warning

For .NET Framework 4.6.1, .NET Core 2.0, Mono 5.4, or higher we recommend using our [.NET SDK](https://docs.sentry.io/platforms/dotnet.md). Raven is still recommended for .NET Framework 3.5 to 4.6.0.

Raven is a legacy client for Sentry written in C#, used in older versions of .NET Framework.

## [Installation](https://docs.sentry.io/.md#installation)

A [NuGet Package](https://www.nuget.org/packages/SharpRaven.md) is available for SharpRaven if you don’t want to compile it yourself.

Instantiate the client with your DSN:

```csharp
var ravenClient = new RavenClient("https://examplePublicKey@o0.ingest.sentry.io/0");
```

## [Capturing Exceptions](https://docs.sentry.io/.md#capturing-exceptions)

Call out to the client in your catch block:

```csharp
try
{
    int i2 = 0;
    int i = 10 / i2;
}
catch (Exception exception)
{
    ravenClient.Capture(new SentryEvent(exception));
}
```

## [Logging Non-Exceptions](https://docs.sentry.io/.md#logging-non-exceptions)

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

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

## [Additional Data](https://docs.sentry.io/.md#additional-data)

You can add additional data to the [Exception.Data](https://msdn.microsoft.com/en-us/library/system.exception.data.aspx) property on exceptions thrown about in your solution:

```csharp
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](https://docs.sentry.io/.md#async-support)

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

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

## [Nancy Support](https://docs.sentry.io/.md#nancy-support)

You can install the [SharpRaven.Nancy](https://www.nuget.org/packages/SharpRaven.Nancy) package to capture the HTTP context in [Nancy](https://nancyfx.org/.md) 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:

```csharp
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{
    container.Register(new Dsn("https://examplePublicKey@o0.ingest.sentry.io/0"));
}
```

or through configuration:

```xml
<configuration>
  <configSections>
    <section
      name="sharpRaven"
      type="SharpRaven.Nancy.NancyConfiguration, SharpRaven.Nancy"
    />
  </configSections>
  <sharpRaven>
    <dsn value="https://examplePublicKey@o0.ingest.sentry.io/0" />
  </sharpRaven>
</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:

```csharp
public class LoggingModule : NancyModule
{
    private readonly IRavenClient ravenClient;

    public LoggingModule(IRavenClient ravenClient)
    {
        this.ravenClient = ravenClient;
    }
}
```

## [Breadcrumbs](https://docs.sentry.io/.md#breadcrumbs)

Sentry supports a concept called [Breadcrumbs](https://docs.sentry.io/platforms/dotnet/enriching-events/breadcrumbs.md), which is a trail of events which happened prior to an issue. Often times these events are very similar to traditional logs, but also have the ability to record more rich structured data.

```csharp
public class ExampleController : ApiController
{
    private readonly IRavenClient ravenClient;

    public ExampleController(IRavenClient ravenClient)
    {
        this.ravenClient = ravenClient;
    }

    public IHttpActionResult GetProduct(int id) {
        ravenClient.AddTrail(new Breadcrumb("example") { Message = "some message...", Level = BreadcrumbLevel.Info } );

        var product = products.FirstOrDefault((p) => p.Id == id);
        if (product == null)
        {
            ravenClient.AddTrail(new Breadcrumb("example") { Message = "Ops! It was not found.", Level = BreadcrumbLevel.Warn } );
            return NotFound();
        }

        return Ok(product);
    }
}
```

## [Debugging SharpRaven](https://docs.sentry.io/.md#debugging-sharpraven)

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

```csharp
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:

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