Exemplo n.º 1
0
        public static LoggerConfiguration DurableLogDNA(
            this LoggerSinkConfiguration sinkConfiguration,
            string apiKey,
            string appName            = null,
            string commaSeparatedTags = null,
            string ingestUrl          = "https://logs.logdna.com/logs/ingest",
            string hostname           = null,
            int?batchPostingLimit     = null,
            string bufferPathFormat   = "logdna-buffer-{Date}.json",
            TimeSpan?period           = null,
            LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum)
        {
            if (sinkConfiguration == null)
            {
                throw new ArgumentNullException(nameof(sinkConfiguration));
            }
            if (string.IsNullOrWhiteSpace(apiKey))
            {
                throw new ArgumentNullException(nameof(apiKey));
            }
            if (string.IsNullOrWhiteSpace(ingestUrl))
            {
                throw new ArgumentNullException(nameof(ingestUrl));
            }

            ingestUrl += (ingestUrl.Contains("?") ? "&" : "?") + $"hostname={hostname ?? Dns.GetHostName().ToLower()}";
            if (commaSeparatedTags != null)
            {
                ingestUrl += $"&tags={WebUtility.UrlEncode(commaSeparatedTags)}";
            }

            var envName = Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ??
                          Environment.GetEnvironmentVariable("ASPNET_ENVIRONMENT");

            return(sinkConfiguration.DurableHttp(ingestUrl,
                                                 bufferPathFormat: bufferPathFormat,
                                                 batchPostingLimit: batchPostingLimit ?? 50,
                                                 period: period ?? TimeSpan.FromSeconds(15),
                                                 textFormatter: new LogdnaTextFormatter(appName ?? "unknown", envName),
                                                 batchFormatter: new LogdnaBatchFormatter(),
                                                 restrictedToMinimumLevel: restrictedToMinimumLevel,
                                                 httpClient: new LogdnaHttpClient(apiKey)));
        }