Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs for ASP.NET 5 / vNext support #51

Open
mikeckennedy opened this issue Apr 26, 2016 · 0 comments
Open

Update docs for ASP.NET 5 / vNext support #51

mikeckennedy opened this issue Apr 26, 2016 · 0 comments

Comments

@mikeckennedy
Copy link

As you may know, the exception filter stuff doesn't work the same in ASP.NET vNext as far as I can tell. The following steps work there instead. Consider updating the docs or adding a separate readme?

Create an ILogger:

public class RollbarExceptionLogger : ILogger
{
    public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func<object, Exception, string> formatter)
    {
        if (exception == null)
            return;

        const string accessToken = "YOUR_SERVER_ACCESS_TOKEN";
        RollbarClient rollbar = new RollbarClient(accessToken);
        rollbar.SendException(exception);
    }

    public bool IsEnabled(LogLevel logLevel)
    {
#if DEBUG
        return false;
#else
        return true;
#endif
    }

    public IDisposable BeginScopeImpl(object state)
    {
        return null;
    }
}

Next create a ILoggerProvider to generate them upon request.

public class RollbarExceptionLoggerProvider : ILoggerProvider
{
    public void Dispose()
    {
    }

    public ILogger CreateLogger(string categoryName)
    {
        return new RollbarExceptionLogger();
    }
}

Finally, install it in your Startup.cs's configure method call:

public class Startup
{
            public void Configure(IApplicationBuilder app, IHostingEnvironment env,
        ILoggerFactory loggerFactory, IOptions<MvcJsonOptions> mvcOptions )
    {
        Environment = env;
        mvcOptions.Value.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
        loggerFactory.AddConsole(Configuration.GetSection("Logging"));
        loggerFactory.AddProvider(new RollbarExceptionLoggerProvider());
        loggerFactory.AddDebug();
                   // ...
           }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant