Giter VIP home page Giter VIP logo

raven-csharp's Introduction

Usage

Instantiate the client with your DSN:

var ravenClient = new RavenClient("http://public:[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 e)
{
    ravenClient.CaptureException(e);
}

Logging Non-Exceptions

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

ravenClient.CaptureMessage("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 capture methods allow you to provide additional data to be sent with your request. CaptureException supports both the tags and extra properties, and CaptureMessage additionally supports the level property.

The full argument specs are:

string CaptureException(Exception exception,
                        SentryMessage message = null,
                        ErrorLevel level = ErrorLevel.Error,
                        IDictionary<string, string> tags = null,
                        string[] fingerprint = null,
                        object extra = null)

string CaptureMessage(SentryMessage message,
                      ErrorLevel level = ErrorLevel.Info,
                      IDictionary<string, string> tags = null,
                      string[] fingerprint = null,
                      object extra = null)

Async Support

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

Task<string> CaptureExceptionAsync(Exception exception,
                                   SentryMessage message = null,
                                   ErrorLevel level = ErrorLevel.Error,
                                   IDictionary<string, string> tags = null,
                                   string[] fingerprint = null,
                                   object extra = null);

Task<string> CaptureMessageAsync(SentryMessage message,
                                 ErrorLevel level = ErrorLevel.Info,
                                 IDictionary<string, string> tags = null,
                                 string[] fingerprint = null,
                                 object extra = null);

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:[email protected]/project-id"));
}

or through configuration:

<configuration>
  <configSections>
    <section name="sharpRaven" type="SharpRaven.Nancy.NancyConfiguration, SharpRaven.Nancy" />
  </configSections>
  <sharpRaven>
    <dsn value="http://public:[email protected]/project-id" />
  </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:

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

Get it!

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

Resources

raven-csharp's People

Contributors

asbjornu avatar dcramer avatar realbrubru avatar xpicio avatar notheotherben avatar mattrobenolt avatar mitsuhiko avatar gregmac avatar timorzadir avatar alex347 avatar galmeida avatar razzmatazz avatar jmalczak avatar andya13 avatar ayodele07 avatar biegal avatar ehfeng avatar ehvattum avatar mbenford avatar mol avatar nielsklosterandreassen avatar rowandh avatar razonrus avatar rustyswayne avatar adamghill avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.