JudahGabriel / RavenDB.StructuredLog

An ASP.NET Core logger that utilizes RavenDB to store structured logs.
https://www.nuget.org/packages/RavenDB.StructuredLogger
MIT License
12 stars 6 forks source link

Different Database and Certificate for logging rather than main cluster #6

Closed bobskigit closed 3 years ago

bobskigit commented 3 years ago

Do you have an example where there are two RavenDB clusters, one for logging and one for main production. The logging and production cluster have different URL's and certificates.

Thanks in Advance

JudahGabriel commented 3 years ago

In Startup.cs when you add the structured logger, you can specify the doc store. Pass in the doc store for the logging cluster:

var loggingClusterDocStore = new DocumentStore(...);
loggingClusterDocStore.IgnoreSelfReferencingLoops();
loggingClusterDocStore.Initialize();

// Tell Raven.StructuredLog to use the logging cluster as its doc store.
services.AddLogging(builder => builder.AddRavenStructuredLogger(loggingClusterDocStore));
bobskigit commented 3 years ago

Doesn't seem to work.

It does not seem to create another RavenDB connection. I am using from your Dependency Injection project for the production cluster?

Any ideas?

JudahGabriel commented 3 years ago

What does your code look like?

bobskigit commented 3 years ago

Startup

      services
            .AddRavenDbDocStore() // 1. Configures Raven connection using the settings in appsettings.json.
            .AddRavenDbAsyncSession();

        var loggingClusterDocStore = new DocumentStore(...);
        loggingClusterDocStore.IgnoreSelfReferencingLoops();
        loggingClusterDocStore.Initialize();

        // Tell Raven.StructuredLog to use the logging cluster as its doc store.
        services.AddLogging(builder => builder.AddRavenStructuredLogger(loggingClusterDocStore));

        services.AddCors(options =>
        {
            options.AddPolicy("CorsPolicy",
                builder => builder.SetIsOriginAllowed((host) => true)
                    .AllowAnyMethod()
                    .AllowAnyHeader()
                    .AllowCredentials());
        });

        services.Configure<APISettings>(
            Configuration.GetSection(nameof(APISettings)));

        services.AddSingleton<IAPISettings>(sp =>
            sp.GetRequiredService<IOptions<APISettings>>().Value);
JudahGabriel commented 3 years ago

I see I don't have an overload to .AddRavenStructuredLogger that accepts a different database.

Updating the code now so that you can do this. I'll post here when a new package is available.

JudahGabriel commented 3 years ago

OK, I've implemented this and published RavenDB.StructuredLogger v6.0.1. It now has the following overload:

services.AddLogging(builder => builder.AddRavenStructuredLogger(docStore));

Use that overload to send in the docStore used for logging. 👍

bobskigit commented 3 years ago

Many thanks