From 200650d00006561e1ad0b6be612a4486e230d666 Mon Sep 17 00:00:00 2001 From: Darryl Shpak Date: Tue, 12 Dec 2017 10:28:48 -0600 Subject: [PATCH 1/3] Add some extra parameters to allow configuration from appsettings.json --- README.md | 23 +++++++++++++++- .../LoggerConfigurationLogglyExtensions.cs | 27 ++++++++++++++++--- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c969e8e..1b1c026 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ var log = new LoggerConfiguration() Properties will be sent along to Loggly. The level is sent as a category. -To use a durable logger (that will save messages localy if the connectio nto the server is unavailable, and resend once the connection has recovered), set the `bufferBaseFilename` argument in the `Loggly()` extension method. +To use a durable logger (that will save messages locally if the connection to the server is unavailable, and resend once the connection has recovered), set the `bufferBaseFilename` argument in the `Loggly()` extension method. ```csharp var log = new LoggerConfiguration() @@ -27,3 +27,24 @@ var log = new LoggerConfiguration() This will write unsent messages to a `buffer-{Date}.json` file in the specified folder (`C:\test\` in the example). The method also takes a `retainedFileCountLimit` parameter that will allow you to control how much info to store / ship when back online. By default, the value is `null` with the intent is to send all persisted data, no matter how old. If you specify a value, only the data in the last N buffer files will be shipped back, preventing stale data to be indexed (if that info is no longer usefull). + +The sink can also be configured from `appsettings.json` for .NET Standard / .NET Core applications that do not support XML configuration: + +```json +{ + "Serilog": { + "WriteTo": [ + { + "Name": "Loggly", + "Args": { + "customerToken": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", + "tags": "foo,bar" + } + } + ], + "Properties": { "Application": "SampleApp" } + } +} +``` + +The `customerToken` argument is required, if you use this form of configuration. The `tags` argument is comma-delimited. The `Application` property will also be sent to Loggly and should be set appropriately. \ No newline at end of file diff --git a/src/Serilog.Sinks.Loggly/LoggerConfigurationLogglyExtensions.cs b/src/Serilog.Sinks.Loggly/LoggerConfigurationLogglyExtensions.cs index a099461..8e4da79 100644 --- a/src/Serilog.Sinks.Loggly/LoggerConfigurationLogglyExtensions.cs +++ b/src/Serilog.Sinks.Loggly/LoggerConfigurationLogglyExtensions.cs @@ -13,6 +13,8 @@ // limitations under the License. using System; +using System.Collections.Generic; +using System.Linq; using Serilog.Configuration; using Serilog.Core; using Serilog.Events; @@ -48,9 +50,12 @@ public static class LoggerConfigurationLogglyExtensions /// The limit is soft in that it can be exceeded by any single error payload, but in that case only that single error /// payload will be retained. /// number of files to retain for the buffer. If defined, this also controls which records + /// in the buffer get sent to the remote Loggly instance + /// Token used to identify the Loggly account to use + /// Comma-delimited list of tags to submit to Loggly + /// Hostname to send logs to. Defaults to logs-01.loggly.com. /// Used to configure underlying LogglyClient programmaticaly. Otherwise use app.Config. /// Decides if the sink should include specific properties in the log message - /// in the buffer get sent to the remote Loggly instance /// Logger configuration, allowing configuration to continue. /// A required parameter is null. public static LoggerConfiguration Loggly( @@ -65,6 +70,9 @@ public static LoggerConfiguration Loggly( LoggingLevelSwitch controlLevelSwitch = null, long? retainedInvalidPayloadsLimitBytes = null, int? retainedFileCountLimit = null, + string customerToken = null, + string tags = null, + string endpointHostName = null, LogglyConfiguration logglyConfig = null, LogIncludes includes = null) { @@ -76,9 +84,22 @@ public static LoggerConfiguration Loggly( ILogEventSink sink; + LogglyConfiguration constructedLogglyConfig = null; + if (customerToken != null) + { + constructedLogglyConfig = new LogglyConfiguration + { + CustomerToken = customerToken, + Tags = tags?.Split(',').ToList() ?? new List(), + EndpointHostName = endpointHostName + }; + } + + var activeLogglyConfig = logglyConfig ?? constructedLogglyConfig; + if (bufferBaseFilename == null) { - sink = new LogglySink(formatProvider, batchPostingLimit, defaultedPeriod, logglyConfig, includes); + sink = new LogglySink(formatProvider, batchPostingLimit, defaultedPeriod, activeLogglyConfig, includes); } else { @@ -92,7 +113,7 @@ public static LoggerConfiguration Loggly( retainedInvalidPayloadsLimitBytes, retainedFileCountLimit, formatProvider, - logglyConfig, + activeLogglyConfig, includes); } From 730f1834ef9467fad4a8c644d276125abee640a8 Mon Sep 17 00:00:00 2001 From: Miguel Alho Date: Tue, 17 Jul 2018 13:53:30 +0100 Subject: [PATCH 2/3] version bump --- src/Serilog.Sinks.Loggly/Serilog.Sinks.Loggly.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Loggly/Serilog.Sinks.Loggly.csproj b/src/Serilog.Sinks.Loggly/Serilog.Sinks.Loggly.csproj index c78deda..7f7a17e 100644 --- a/src/Serilog.Sinks.Loggly/Serilog.Sinks.Loggly.csproj +++ b/src/Serilog.Sinks.Loggly/Serilog.Sinks.Loggly.csproj @@ -2,7 +2,7 @@ Serilog sink for Loggly.com service - 5.2.0 + 5.3.0 Serilog Contributors;Michiel van Oudheusden net45;netstandard1.5 Serilog.Sinks.Loggly From cf3da3b84d4dd7a676ab1b62dd8097b50507afb9 Mon Sep 17 00:00:00 2001 From: Matthew Erbs Date: Wed, 18 Jul 2018 16:27:16 +1000 Subject: [PATCH 3/3] Update NuGet API Key. --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index da14701..05033c0 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -14,7 +14,7 @@ artifacts: deploy: - provider: NuGet api_key: - secure: nvZ/z+pMS91b3kG4DgfES5AcmwwGoBYQxr9kp4XiJHj25SAlgdIxFx++1N0lFH2x + secure: bd9z4P73oltOXudAjPehwp9iDKsPtC+HbgshOrSgoyQKr5xVK+bxJQngrDJkHdY8 skip_symbols: true on: branch: /^(master|dev)$/