Rollbar.NET icon indicating copy to clipboard operation
Rollbar.NET copied to clipboard

AddRollbarProvider from ILoggingBuilder .Net Core

Open mymys91 opened this issue 4 years ago • 8 comments

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):

  • .NET flavor and its version: .NET Core 3.0
  • Rollbar.NET Version: 3.7.1

Additional context From Rollbar sourecode, I see function ILoggingBuilder AddRollbar try add RollbarLoggerFactory, I do not understand its purpose.

mymys91 avatar Mar 27 '20 07:03 mymys91

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

akornich avatar Mar 27 '20 20:03 akornich

confirm, Console logger is removed.

Lechus avatar Mar 30 '20 10:03 Lechus

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.

Lechus avatar Mar 30 '20 11:03 Lechus

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

akornich avatar Mar 30 '20 17:03 akornich

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

mymys91 avatar Apr 01 '20 04:04 mymys91

@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?

akornich avatar Apr 07 '20 07:04 akornich

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.

Lechus avatar Apr 09 '20 10:04 Lechus

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

akornich avatar Jul 01 '20 17:07 akornich