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

CouchDB.NET logging #134

Open
AlexandrSHad opened this issue Aug 2, 2021 · 4 comments
Open

CouchDB.NET logging #134

AlexandrSHad opened this issue Aug 2, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@AlexandrSHad
Copy link
Contributor

Hi!
I'd like to know how do you perform logging?
I get that it is possible via Flurl using AfterCall event and ConfigureFlurlClient() method. But I think it would be better CouchDB.NET provides its own logging system. In this case to enable logging the only thing to do is to change the logging level in an appsettings.json. Do you have any plans regarding this? Or what is your logging strategy?

@matteobortolazzo
Copy link
Owner

Hi,

at the moment there is no built-in Logger.
Do you think something like is ok? EF Core logging

Seems like a lot of work tho. So I will give a deeper look one I have time to take all the issues and bring the next major release

@matteobortolazzo matteobortolazzo added the enhancement New feature or request label Aug 3, 2021
@AlexandrSHad
Copy link
Contributor Author

I meant exactly integration with Microsoft.Extensions.Logging. And to be honest I did not know about simple logging in EF)
While simple logging is a cool feature, but I more care about logging in production.
We are using the Autofac DI container and Serilog for logging. To set up all this stuff I need to do something like this:

    public static class AutofacRegistrationExtensions
    {
        public static ContainerBuilder AddCouchContext<TContext>(
            this ContainerBuilder containerBuilder,
            Action<CouchOptionsBuilder<TContext>> optionBuilderAction)
            where TContext : CouchContext
        {
            var optionsBuilder = new CouchOptionsBuilder<TContext>();
            optionBuilderAction?.Invoke(optionsBuilder);

            containerBuilder.Register(ctx =>
            {
                var logger = ctx.Resolve<ILogger<TContext>>();

                optionsBuilder
                    .ConfigureFlurlClient(cfg =>
                    {
                        cfg.AfterCall = (call) => logger.LogDebug($"{call.Request.Verb} {call.Request.Url}: {call.RequestBody}")
                    });

                return optionsBuilder.Options;
            });

            containerBuilder.RegisterType<TContext>().SingleInstance();

            return containerBuilder;
        }
    }

Looks a bit weird, doesn't it?
In case CouchDB.NET were to have a logging system integrated with Microsoft.Extensions.Logging I would not have to use ConfigureFlurlClient() method at all. I would only register context during startup and set up the required log level in an application configuration.

{
  "Serilog": {
    "MinimumLevel": {
      "Default": "Information",
      "Override": {
        "MassTransit": "Debug",
        "CouchDB.NET": "Debug"
      }
    }
  }
}

This is applicable to any 3-rd party Logging libraries or even Microsoft.Extensions.Logging itself so that is an additional advantage.

@matteobortolazzo
Copy link
Owner

I got. To be honest I prefer to do a proper implementation. I should be able to work on it in the coming weeks

@AlexandrSHad
Copy link
Contributor Author

Ok.
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants