コード例 #1
0
        private static RavenStructuredLoggerProvider CreateLogProvider(IServiceProvider provider, IDocumentStore?docStore, Action <LogOptions>?configAction)
        {
            var config  = provider.GetRequiredService <IConfiguration>();
            var db      = docStore ?? provider.GetRequiredService <IDocumentStore>();
            var options = new LogOptions();

            if (int.TryParse(config["Logging:MaxOccurrences"], out var maxOccurrences))
            {
                options.MaxOccurrences = maxOccurrences;
            }

            // See if we're configured to use scopes.
            if (bool.TryParse(config["Logging:IncludeScopes"], out var includeScopes))
            {
                options.IncludeScopes = includeScopes;
            }

            // See if we're configured to expire logs.
            if (int.TryParse(config["Logging:ExpirationInDays"], out var expirationInDays))
            {
                options.ExpirationInDays = expirationInDays;
            }

            // See if we're configured to expire logs.
            if (float.TryParse(config["Logging:FuzzyLogSearchAccuracy"], out var fuzzyLogSearchAccuracy))
            {
                options.FuzzyLogSearchAccuracy = fuzzyLogSearchAccuracy;
            }

            configAction?.Invoke(options);
            return(new RavenStructuredLoggerProvider(db, options));
        }
コード例 #2
0
 /// <summary>
 /// Creates a new structured logger.
 /// </summary>
 /// <param name="categoryName">The name of the logger.</param>
 /// <param name="db">The Raven <see cref="IDocumentStore"/>.</param>
 /// <param name="options">The logger options containing log configuration.</param>
 public RavenStructuredLogger(string categoryName, IDocumentStore db, LogOptions options)
 {
     this.categoryName = categoryName;
     this.db           = db;
     this.options      = options;
 }
コード例 #3
0
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 /// <param name="db">The Raven document store to send the logs to.</param>
 /// <param name="options">The log options.</param>
 public RavenStructuredLoggerProvider(IDocumentStore db, LogOptions options)
 {
     this.db      = db ?? throw new ArgumentNullException(nameof(db));
     this.options = options ?? throw new ArgumentNullException(nameof(options));
 }