rollbar / Rollbar.NET

Rollbar for .NET
https://docs.rollbar.com/docs/dotnet
MIT License
65 stars 44 forks source link

AddRollbarProvider from ILoggingBuilder .Net Core #511

Open mymys91 opened 4 years ago

mymys91 commented 4 years ago

Describe the bug Hi, I am not sure this is a bug or not. When I try to add Rollbar provider in ConfigureLogging as same as I do with AddConsole(). It will create 2 LoggerFactory and lead to cannot log to Console anymore. Expected behavior I expect that default LoggerFactory will have 2 providers: console & rollbar.

To Reproduce

  1. Create a new project with template type Worker Service
  2. Add Rollbar accesstoken & Environment to appsetting.json
  3. AddRollbar as in below picture.

Screenshots image

Rollbar Client - Rollbar.NET Hosting Environment (please complete the following information):

akornich commented 4 years ago

@mymys91 , thanks for reporting the issue! I'll look into it probably early next week.

Lechus commented 4 years ago

confirm, Console logger is removed.

Lechus commented 4 years ago

I am using Rollbar.NetCore.AspNet project directly: with stripped out depedency on HttpContextAncestor and some other mods and this works, does not remove Console logger.

Any chance to have a Rollbar.NetCore package with : RollbarServiceCollectionExtensions public static IServiceCollection AddRollbarLogger(this IServiceCollection services){} RollbarServiceCollectionExtensions - without dependency on Http? I think the request is already on Issues.

akornich commented 4 years ago

@Lechus , thanks for the feedback! I think I should be able to dedicate some time to these topics within the next couple of weeks.

mymys91 commented 4 years ago

Hello, Today I try including libraries Rollbar & Rollbar.NetCore.AspNet source code for debugging another need that I want to log error while building host (ASPNETCore 3.1). However, the message didn't send to rollbar, what I can work around is make a Thread sleep 5s 💃

By the way, I comment the line register factory to check my reported issue. What I can see now that loggerfactory has 2 providers: rollbar & console --> they work well

image

akornich commented 4 years ago

@Lechus , i just wanted to clarify something regarding your request to create

"Any chance to have a Rollbar.NetCore package with : RollbarServiceCollectionExtensions public static IServiceCollection AddRollbarLogger(this IServiceCollection services){} RollbarServiceCollectionExtensions - without dependency on Http?"

Is the reason for it to have just Rollbar logger integration with .NET Core dependency injection infrastructure regardless of it to be used within an ASP.NET Core based application?

Lechus commented 4 years ago

WorkerService is not using ASP / HTTP things. I reviewed your latest changes and the netPlatfromExtension looks good. BTW: No need for RollbarLoggerFactory class?

In Programcs CreateHostBuilder(): I added these calls and it is working. ConfigureRollbarSingleton()

services.AddRollbarLogger(loggerOptions =>
                        {
                            loggerOptions.Filter = (loggerName, loglevel) => loglevel >= LogLevel.Error;
                        });

Would be good to have configuration inside AddRollbarLogger?

services.AddRollbarLogger(loggerOptions =>
                        {
                            loggerOptions.Filter = (loggerName, loglevel) => loglevel >= LogLevel.Error;
loggerConfig = (happy default read from Configuration, like rollbar.token and rollbar.environment)
                        });

or provide IRollbarConfig , so a class like MyRollbarConfig with properties like token, env could be populated from ENV / appsettings properties passed to .NET Core IConfiguration.

akornich commented 4 years ago

reopening. i think we can implement a few good points brought up in this thread...