Giter VIP home page Giter VIP logo

rayguncore's Introduction

Raygun provider for .NET Core 2.0

Standart Raygun4Net library does not work well with .NET Core 2.0. So I've created library for new architecture:

  • Built with interfaces and works via default dependency injection;
  • As result, services can be easily extended or replaced;
  • You can work via IRaygunClient directly or use RaygunLogger or intergrate handler into ASP.NET Core pipeline.

Installation via NuGet

Package Description NuGet
RaygunCore Raygun client and logger NuGet
RaygunCore.AspNetCore Handler for ASP.NET Core request pipeline NuGet

How to use with ASP.NET Core

Register services in Startup class:

public void ConfigureServices(IServiceCollection services)
{
    // configure with API KEY
    services.AddRaygun("_API_KEY_")
        .WithHttp();

    // or with options
    services.AddRaygun(opt => opt.ApiKey = "_API_KEY_")
        .WithHttp();

    // or with configuration section
    services.AddRaygun(configuration)
        .WithHttp();
}

Method AddRaygun() registers only minimal required services. So then you can request IRaygunClient service and send errors:

public async Task<string> ActionInController([FromServices]IRaygunClient raygun)
{
    try
    {
        // some code
    }
    catch (Exception ex)
    {
        await raygun.SendAsync(ex);
    }
    return "OK";
}

Method WithHttp() in application services registration adds pipeline handler so any exception in request is automatically sent to Raygun.

How to use with logging

You can register Raygun logger provider:

WebHost.CreateDefaultBuilder(args)
    .UseStartup<Startup>()
    .ConfigureLogging((context, logging) => logging
        .AddRaygun(r => r
            .Configure(opt => opt.ApiKey = "_API_KEY_")
            .WithHttp()
        )
    );

Then just use logger:

public async Task<string> ActionInController([FromServices]ILogger<MyController> logger)
{
    logger.LogError(0, "My error message");
}

License

This package has MIT license. Refer to the LICENSE for detailed information.

rayguncore's People

Contributors

alexgritton avatar anfomin avatar thoemmi avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  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.