From 618d85ff341529b686d2c9432ad153e929ab4833 Mon Sep 17 00:00:00 2001 From: Thomas Vilhelmsen Date: Wed, 29 Nov 2017 13:24:06 +0100 Subject: [PATCH 01/10] Enable programmatic configuration of Loggly c-sharp client --- .../LoggerConfigurationLogglyExtensions.cs | 9 ++- .../Sinks/Loggly/DurableLogglySink.cs | 7 ++- .../Sinks/Loggly/HttpLogShipper.cs | 12 +++- .../Sinks/Loggly/LogglyConfigAdapter.cs | 41 +++++++++++++ .../Sinks/Loggly/LogglyConfiguration.cs | 57 +++++++++++++++++++ .../Sinks/Loggly/LogglySink.cs | 9 ++- .../Serilog.Sinks.Loggly.Tests.csproj | 8 +-- 7 files changed, 130 insertions(+), 13 deletions(-) create mode 100644 src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglyConfigAdapter.cs create mode 100644 src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglyConfiguration.cs diff --git a/src/Serilog.Sinks.Loggly/LoggerConfigurationLogglyExtensions.cs b/src/Serilog.Sinks.Loggly/LoggerConfigurationLogglyExtensions.cs index 58e060f..1905484 100644 --- a/src/Serilog.Sinks.Loggly/LoggerConfigurationLogglyExtensions.cs +++ b/src/Serilog.Sinks.Loggly/LoggerConfigurationLogglyExtensions.cs @@ -48,6 +48,7 @@ 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 + /// Used to configure underlying LogglyClient programmaticaly. Otherwise use app.Config. /// in the buffer get sent to the remote Loggly instance /// Logger configuration, allowing configuration to continue. /// A required parameter is null. @@ -62,7 +63,8 @@ public static LoggerConfiguration Loggly( long? eventBodyLimitBytes = 1024 * 1024, LoggingLevelSwitch controlLevelSwitch = null, long? retainedInvalidPayloadsLimitBytes = null, - int? retainedFileCountLimit = null) + int? retainedFileCountLimit = null, + LogglyConfiguration logglyConfig = null) { if (loggerConfiguration == null) throw new ArgumentNullException(nameof(loggerConfiguration)); if (bufferFileSizeLimitBytes.HasValue && bufferFileSizeLimitBytes < 0) @@ -74,7 +76,7 @@ public static LoggerConfiguration Loggly( if (bufferBaseFilename == null) { - sink = new LogglySink(formatProvider, batchPostingLimit, defaultedPeriod); + sink = new LogglySink(formatProvider, batchPostingLimit, defaultedPeriod, logglyConfig); } else { @@ -87,7 +89,8 @@ public static LoggerConfiguration Loggly( controlLevelSwitch, retainedInvalidPayloadsLimitBytes, retainedFileCountLimit, - formatProvider); + formatProvider, + logglyConfig); } return loggerConfiguration.Sink(sink, restrictedToMinimumLevel); diff --git a/src/Serilog.Sinks.Loggly/Sinks/Loggly/DurableLogglySink.cs b/src/Serilog.Sinks.Loggly/Sinks/Loggly/DurableLogglySink.cs index 4247754..9430582 100644 --- a/src/Serilog.Sinks.Loggly/Sinks/Loggly/DurableLogglySink.cs +++ b/src/Serilog.Sinks.Loggly/Sinks/Loggly/DurableLogglySink.cs @@ -34,8 +34,8 @@ public DurableLogglySink( LoggingLevelSwitch levelControlSwitch, long? retainedInvalidPayloadsLimitBytes, int? retainedFileCountLimit = null, - IFormatProvider formatProvider = null - ) + IFormatProvider formatProvider = null, + LogglyConfiguration logglyConfiguration = null) { if (bufferBaseFilename == null) throw new ArgumentNullException(nameof(bufferBaseFilename)); @@ -51,7 +51,8 @@ public DurableLogglySink( levelControlSwitch, retainedInvalidPayloadsLimitBytes, encoding, - retainedFileCountLimit); + retainedFileCountLimit, + logglyConfiguration); //writes events to the file to support connection recovery _sink = new RollingFileSink( diff --git a/src/Serilog.Sinks.Loggly/Sinks/Loggly/HttpLogShipper.cs b/src/Serilog.Sinks.Loggly/Sinks/Loggly/HttpLogShipper.cs index ef00ffe..01b82dc 100644 --- a/src/Serilog.Sinks.Loggly/Sinks/Loggly/HttpLogShipper.cs +++ b/src/Serilog.Sinks.Loggly/Sinks/Loggly/HttpLogShipper.cs @@ -43,7 +43,8 @@ class HttpLogShipper : IDisposable readonly IFileSystemAdapter _fileSystemAdapter = new FileSystemAdapter(); readonly FileBufferDataProvider _bufferDataProvider; readonly InvalidPayloadLogger _invalidPayloadLogger; - + readonly LogglyConfigAdapter _adapter; + public HttpLogShipper( string bufferBaseFilename, int batchPostingLimit, @@ -52,7 +53,8 @@ public HttpLogShipper( LoggingLevelSwitch levelControlSwitch, long? retainedInvalidPayloadsLimitBytes, Encoding encoding, - int? retainedFileCountLimit) + int? retainedFileCountLimit, + LogglyConfiguration logglyConfiguration) { _batchPostingLimit = batchPostingLimit; _retainedFileCountLimit = retainedFileCountLimit; @@ -60,6 +62,12 @@ public HttpLogShipper( _controlledSwitch = new ControlledLevelSwitch(levelControlSwitch); _connectionSchedule = new ExponentialBackoffConnectionSchedule(period); + if (logglyConfiguration != null) + { + _adapter = new LogglyConfigAdapter(); + _adapter.ConfigureLogglyClient(logglyConfiguration); + } + _logglyClient = new LogglyClient(); //we'll use the loggly client instead of HTTP directly //create necessary path elements diff --git a/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglyConfigAdapter.cs b/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglyConfigAdapter.cs new file mode 100644 index 0000000..ae1a29f --- /dev/null +++ b/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglyConfigAdapter.cs @@ -0,0 +1,41 @@ +using System; +using Loggly.Config; + +namespace Serilog.Sinks.Loggly +{ + class LogglyConfigAdapter + { + public void ConfigureLogglyClient(LogglyConfiguration logglyConfiguration) + { + var config = LogglyConfig.Instance; + + if (!string.IsNullOrWhiteSpace(logglyConfiguration.ApplicationName)) + config.ApplicationName = logglyConfiguration.ApplicationName; + + if (string.IsNullOrWhiteSpace(logglyConfiguration.CustomerToken)) + throw new ArgumentNullException("CustomerToken", "CustomerToken is required"); + + config.CustomerToken = logglyConfiguration.CustomerToken; + config.IsEnabled = logglyConfiguration.IsEnabled; + + foreach (var tag in logglyConfiguration.Tags) + { + config.TagConfig.Tags.Add(tag); + } + + config.ThrowExceptions = logglyConfiguration.ThrowExceptions; + + if (logglyConfiguration.LogTransport != TransportProtocol.Https) + config.Transport.LogTransport = (LogTransport)Enum.Parse(typeof(LogTransport), logglyConfiguration.LogTransport.ToString()); + + if (!string.IsNullOrWhiteSpace(logglyConfiguration.EndpointHostName)) + config.Transport.EndpointHostname = logglyConfiguration.EndpointHostName; + + if (logglyConfiguration.EndpointPort > 0 && logglyConfiguration.EndpointPort < ushort.MaxValue) + config.Transport.EndpointPort = logglyConfiguration.EndpointPort; + + config.Transport.IsOmitTimestamp = logglyConfiguration.OmitTimestamp; + config.Transport = config.Transport.GetCoercedToValidConfig(); + } + } +} diff --git a/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglyConfiguration.cs b/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglyConfiguration.cs new file mode 100644 index 0000000..ec1b4a5 --- /dev/null +++ b/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglyConfiguration.cs @@ -0,0 +1,57 @@ +using System.Collections.Generic; + +namespace Serilog.Sinks.Loggly +{ + public class LogglyConfiguration + { + public string ApplicationName { get; set; } + public string CustomerToken { get; set; } + public List Tags { get; set; } + public bool IsEnabled { get; set; } = true; + public bool ThrowExceptions { get; set; } + + /// + /// Defaults to Https + /// + public TransportProtocol LogTransport { get; set; } + + /// + /// Defaults to logs-01.loggly.com + /// + public string EndpointHostName { get; set; } + + /// + /// Defaults to default port for selected LogTransport. + /// E.g. https is 443, SyslogTcp/-Udp is 514 and SyslogSecure is 6514. + /// + public int EndpointPort { get; set; } + + /// + /// Defines if timestamp should automatically be added to the json body when using Https + /// + public bool OmitTimestamp { get; set; } + } + + public enum TransportProtocol + { + /// + /// Https. + /// + Https, + + /// + /// SyslogSecure. + /// + SyslogSecure, + + /// + /// SyslogUdp. + /// + SyslogUdp, + + /// + /// SyslogTcp. + /// + SyslogTcp, + } +} diff --git a/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglySink.cs b/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglySink.cs index 6cefa6f..eb14aa6 100644 --- a/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglySink.cs +++ b/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglySink.cs @@ -29,6 +29,7 @@ public class LogglySink : PeriodicBatchingSink { readonly LogEventConverter _converter; readonly LogglyClient _client; + readonly LogglyConfigAdapter _adapter; /// /// A reasonable default for the number of events posted in @@ -47,9 +48,15 @@ public class LogglySink : PeriodicBatchingSink /// The maximum number of events to post in a single batch. /// The time to wait between checking for event batches. /// Supplies culture-specific formatting information, or null. - public LogglySink(IFormatProvider formatProvider, int batchSizeLimit, TimeSpan period) + /// Used to configure underlying LogglyClient programmaticaly. Otherwise use app.Config. + public LogglySink(IFormatProvider formatProvider, int batchSizeLimit, TimeSpan period, LogglyConfiguration logglyConfig) : base (batchSizeLimit, period) { + if (logglyConfig != null) + { + _adapter = new LogglyConfigAdapter(); + _adapter.ConfigureLogglyClient(logglyConfig); + } _client = new LogglyClient(); _converter = new LogEventConverter(formatProvider); } diff --git a/test/Serilog.Sinks.Loggly.Tests/Serilog.Sinks.Loggly.Tests.csproj b/test/Serilog.Sinks.Loggly.Tests/Serilog.Sinks.Loggly.Tests.csproj index 1b67e3f..7cd58f0 100644 --- a/test/Serilog.Sinks.Loggly.Tests/Serilog.Sinks.Loggly.Tests.csproj +++ b/test/Serilog.Sinks.Loggly.Tests/Serilog.Sinks.Loggly.Tests.csproj @@ -32,10 +32,10 @@ - - - - + + + + From 3bcad39d3dd83179cfcda8d0429265ae3a50789a Mon Sep 17 00:00:00 2001 From: Thomas Vilhelmsen Date: Wed, 29 Nov 2017 21:25:24 +0100 Subject: [PATCH 02/10] Enable control of properties automatically added to Loggly events --- .../LoggerConfigurationLogglyExtensions.cs | 9 ++++++--- .../Sinks/Loggly/DurableLogglySink.cs | 5 +++-- .../Sinks/Loggly/LogEventConverter.cs | 18 ++++++++++------- .../Sinks/Loggly/LogIncludes.cs | 20 +++++++++++++++++++ .../Sinks/Loggly/LogglyFormatter.cs | 4 ++-- .../Sinks/Loggly/LogglySink.cs | 5 +++-- .../ExceptionSerialization.cs | 2 +- 7 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 src/Serilog.Sinks.Loggly/Sinks/Loggly/LogIncludes.cs diff --git a/src/Serilog.Sinks.Loggly/LoggerConfigurationLogglyExtensions.cs b/src/Serilog.Sinks.Loggly/LoggerConfigurationLogglyExtensions.cs index 1905484..a099461 100644 --- a/src/Serilog.Sinks.Loggly/LoggerConfigurationLogglyExtensions.cs +++ b/src/Serilog.Sinks.Loggly/LoggerConfigurationLogglyExtensions.cs @@ -49,6 +49,7 @@ public static class LoggerConfigurationLogglyExtensions /// payload will be retained. /// number of files to retain for the buffer. If defined, this also controls which records /// 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. @@ -64,7 +65,8 @@ public static LoggerConfiguration Loggly( LoggingLevelSwitch controlLevelSwitch = null, long? retainedInvalidPayloadsLimitBytes = null, int? retainedFileCountLimit = null, - LogglyConfiguration logglyConfig = null) + LogglyConfiguration logglyConfig = null, + LogIncludes includes = null) { if (loggerConfiguration == null) throw new ArgumentNullException(nameof(loggerConfiguration)); if (bufferFileSizeLimitBytes.HasValue && bufferFileSizeLimitBytes < 0) @@ -76,7 +78,7 @@ public static LoggerConfiguration Loggly( if (bufferBaseFilename == null) { - sink = new LogglySink(formatProvider, batchPostingLimit, defaultedPeriod, logglyConfig); + sink = new LogglySink(formatProvider, batchPostingLimit, defaultedPeriod, logglyConfig, includes); } else { @@ -90,7 +92,8 @@ public static LoggerConfiguration Loggly( retainedInvalidPayloadsLimitBytes, retainedFileCountLimit, formatProvider, - logglyConfig); + logglyConfig, + includes); } return loggerConfiguration.Sink(sink, restrictedToMinimumLevel); diff --git a/src/Serilog.Sinks.Loggly/Sinks/Loggly/DurableLogglySink.cs b/src/Serilog.Sinks.Loggly/Sinks/Loggly/DurableLogglySink.cs index 9430582..cbb01b1 100644 --- a/src/Serilog.Sinks.Loggly/Sinks/Loggly/DurableLogglySink.cs +++ b/src/Serilog.Sinks.Loggly/Sinks/Loggly/DurableLogglySink.cs @@ -35,7 +35,8 @@ public DurableLogglySink( long? retainedInvalidPayloadsLimitBytes, int? retainedFileCountLimit = null, IFormatProvider formatProvider = null, - LogglyConfiguration logglyConfiguration = null) + LogglyConfiguration logglyConfiguration = null, + LogIncludes includes = null) { if (bufferBaseFilename == null) throw new ArgumentNullException(nameof(bufferBaseFilename)); @@ -57,7 +58,7 @@ public DurableLogglySink( //writes events to the file to support connection recovery _sink = new RollingFileSink( bufferBaseFilename + "-{Date}.json", - new LogglyFormatter(formatProvider), //serializes as LogglyEvent + new LogglyFormatter(formatProvider, includes), //serializes as LogglyEvent bufferFileSizeLimitBytes, retainedFileCountLimit, encoding); diff --git a/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogEventConverter.cs b/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogEventConverter.cs index 1fe2ea2..29c17e8 100644 --- a/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogEventConverter.cs +++ b/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogEventConverter.cs @@ -16,10 +16,12 @@ namespace Serilog.Sinks.Loggly public class LogEventConverter { readonly IFormatProvider _formatProvider; + private readonly LogIncludes _includes; - public LogEventConverter(IFormatProvider formatProvider = null) + public LogEventConverter(IFormatProvider formatProvider = null, LogIncludes includes = null) { _formatProvider = formatProvider; + _includes = includes ?? new LogIncludes(); } public LogglyEvent CreateLogglyEvent(LogEvent logEvent) @@ -28,9 +30,11 @@ public LogglyEvent CreateLogglyEvent(LogEvent logEvent) var isHttpTransport = LogglyConfig.Instance.Transport.LogTransport == LogTransport.Https; logglyEvent.Syslog.Level = ToSyslogLevel(logEvent); - - - logglyEvent.Data.AddIfAbsent("Message", logEvent.RenderMessage(_formatProvider)); + + if (_includes.IncludeMessage) + { + logglyEvent.Data.AddIfAbsent("Message", logEvent.RenderMessage(_formatProvider)); + } foreach (var key in logEvent.Properties.Keys) { @@ -39,20 +43,20 @@ public LogglyEvent CreateLogglyEvent(LogEvent logEvent) logglyEvent.Data.AddIfAbsent(key, simpleValue); } - if (isHttpTransport) + if (isHttpTransport && _includes.IncludeLevel) { // syslog will capture these via the header logglyEvent.Data.AddIfAbsent("Level", logEvent.Level.ToString()); } - if (logEvent.Exception != null) + if (logEvent.Exception != null && _includes.IncludeExceptionWhenExists) { logglyEvent.Data.AddIfAbsent("Exception", GetExceptionInfo(logEvent.Exception)); } + return logglyEvent; } - static SyslogLevel ToSyslogLevel(LogEvent logEvent) { SyslogLevel syslogLevel; diff --git a/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogIncludes.cs b/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogIncludes.cs new file mode 100644 index 0000000..288e4aa --- /dev/null +++ b/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogIncludes.cs @@ -0,0 +1,20 @@ +namespace Serilog.Sinks.Loggly +{ + public class LogIncludes + { + /// + /// Adds Serilog Level to all log events. Defaults to true. + /// + public bool IncludeLevel { get; set; } = true; + + /// + /// Adds Serilog Message to all log events. Defaults to true. + /// + public bool IncludeMessage { get; set; } = true; + + /// + /// Adds Serilog Exception to log events when an exception exists. Defaults to true. + /// + public bool IncludeExceptionWhenExists { get; set; } = true; + } +} \ No newline at end of file diff --git a/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglyFormatter.cs b/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglyFormatter.cs index 52dd9c9..903e327 100644 --- a/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglyFormatter.cs +++ b/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglyFormatter.cs @@ -28,11 +28,11 @@ class LogglyFormatter : ITextFormatter readonly JsonSerializer _serializer = JsonSerializer.Create(); readonly LogEventConverter _converter; - public LogglyFormatter(IFormatProvider formatProvider) + public LogglyFormatter(IFormatProvider formatProvider, LogIncludes includes) { //the converter should receive the format provider used, in order to // handle dateTimes and dateTimeOffsets in a controlled manner - _converter = new LogEventConverter(formatProvider); + _converter = new LogEventConverter(formatProvider, includes); } public void Format(LogEvent logEvent, TextWriter output) { diff --git a/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglySink.cs b/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglySink.cs index eb14aa6..983c525 100644 --- a/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglySink.cs +++ b/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglySink.cs @@ -49,7 +49,8 @@ public class LogglySink : PeriodicBatchingSink /// The time to wait between checking for event batches. /// Supplies culture-specific formatting information, or null. /// Used to configure underlying LogglyClient programmaticaly. Otherwise use app.Config. - public LogglySink(IFormatProvider formatProvider, int batchSizeLimit, TimeSpan period, LogglyConfiguration logglyConfig) + /// Decides if the sink should include specific properties in the log message + public LogglySink(IFormatProvider formatProvider, int batchSizeLimit, TimeSpan period, LogglyConfiguration logglyConfig, LogIncludes includes) : base (batchSizeLimit, period) { if (logglyConfig != null) @@ -58,7 +59,7 @@ public LogglySink(IFormatProvider formatProvider, int batchSizeLimit, TimeSpan p _adapter.ConfigureLogglyClient(logglyConfig); } _client = new LogglyClient(); - _converter = new LogEventConverter(formatProvider); + _converter = new LogEventConverter(formatProvider, includes); } /// diff --git a/test/Serilog.Sinks.Loggly.Tests/ExceptionSerialization.cs b/test/Serilog.Sinks.Loggly.Tests/ExceptionSerialization.cs index 7e20b6a..81391b5 100644 --- a/test/Serilog.Sinks.Loggly.Tests/ExceptionSerialization.cs +++ b/test/Serilog.Sinks.Loggly.Tests/ExceptionSerialization.cs @@ -17,7 +17,7 @@ public class ExceptionSerialization public void ReturnFalseGivenValueOf1() { var writer = new StringWriter(); - var formatter = new LogglyFormatter(null); + var formatter = new LogglyFormatter(null, null); try { ThrowException(); From 8a777d7953ec2fa5212aa2bb256add8d3b1b761d Mon Sep 17 00:00:00 2001 From: Thomas Vilhelmsen Date: Thu, 30 Nov 2017 09:32:23 +0100 Subject: [PATCH 03/10] Include max port --- src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglyConfigAdapter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglyConfigAdapter.cs b/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglyConfigAdapter.cs index ae1a29f..ce4ea46 100644 --- a/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglyConfigAdapter.cs +++ b/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglyConfigAdapter.cs @@ -31,7 +31,7 @@ public void ConfigureLogglyClient(LogglyConfiguration logglyConfiguration) if (!string.IsNullOrWhiteSpace(logglyConfiguration.EndpointHostName)) config.Transport.EndpointHostname = logglyConfiguration.EndpointHostName; - if (logglyConfiguration.EndpointPort > 0 && logglyConfiguration.EndpointPort < ushort.MaxValue) + if (logglyConfiguration.EndpointPort > 0 && logglyConfiguration.EndpointPort <= ushort.MaxValue) config.Transport.EndpointPort = logglyConfiguration.EndpointPort; config.Transport.IsOmitTimestamp = logglyConfiguration.OmitTimestamp; From 6d56497304d829af1020175d47efbb869740c62f Mon Sep 17 00:00:00 2001 From: Thomas Vilhelmsen Date: Thu, 30 Nov 2017 10:01:55 +0100 Subject: [PATCH 04/10] Updated version --- src/Serilog.Sinks.Loggly/Properties/AssemblyInfo.cs | 2 +- src/Serilog.Sinks.Loggly/Serilog.Sinks.Loggly.csproj | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Loggly/Properties/AssemblyInfo.cs b/src/Serilog.Sinks.Loggly/Properties/AssemblyInfo.cs index 5269bcb..ac76148 100644 --- a/src/Serilog.Sinks.Loggly/Properties/AssemblyInfo.cs +++ b/src/Serilog.Sinks.Loggly/Properties/AssemblyInfo.cs @@ -2,7 +2,7 @@ using System.Reflection; using System.Runtime.CompilerServices; -[assembly: AssemblyVersion("3.0.0.0")] +[assembly: AssemblyVersion("3.1.0.0")] [assembly: CLSCompliant(true)] diff --git a/src/Serilog.Sinks.Loggly/Serilog.Sinks.Loggly.csproj b/src/Serilog.Sinks.Loggly/Serilog.Sinks.Loggly.csproj index 1090cc6..90698c4 100644 --- a/src/Serilog.Sinks.Loggly/Serilog.Sinks.Loggly.csproj +++ b/src/Serilog.Sinks.Loggly/Serilog.Sinks.Loggly.csproj @@ -16,6 +16,8 @@ http://www.apache.org/licenses/LICENSE-2.0 false Serilog + 5.2.0.0 + 5.2.0 From 048639353f38b729f9616b659ec25d7324f2f938 Mon Sep 17 00:00:00 2001 From: Thomas Vilhelmsen Date: Thu, 30 Nov 2017 12:47:46 +0100 Subject: [PATCH 05/10] Added constructor overload --- src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglySink.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglySink.cs b/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglySink.cs index 983c525..149fc1b 100644 --- a/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglySink.cs +++ b/src/Serilog.Sinks.Loggly/Sinks/Loggly/LogglySink.cs @@ -42,6 +42,16 @@ public class LogglySink : PeriodicBatchingSink /// public static readonly TimeSpan DefaultPeriod = TimeSpan.FromSeconds(5); + /// + /// Construct a sink that saves logs to the specified storage account. Properties are being send as data and the level is used as tag. + /// + /// The maximum number of events to post in a single batch. + /// The time to wait between checking for event batches. + /// Supplies culture-specific formatting information, or null. + public LogglySink(IFormatProvider formatProvider, int batchSizeLimit, TimeSpan period) : this(formatProvider, batchSizeLimit, period, null, null) + { + } + /// /// Construct a sink that saves logs to the specified storage account. Properties are being send as data and the level is used as tag. /// From b55578a3054bf49a9a49922a3d21e3d66187e00d Mon Sep 17 00:00:00 2001 From: Thomas Vilhelmsen Date: Fri, 1 Dec 2017 09:15:20 +0100 Subject: [PATCH 06/10] Bumped VersionPrefix to match version --- 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 90698c4..bcc2730 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.1.1 + 5.2.0 Serilog Contributors;Michiel van Oudheusden net45;netstandard1.5 Serilog.Sinks.Loggly From ec0ea02d775d12656072e9014100a9983e35a5f9 Mon Sep 17 00:00:00 2001 From: Miguel Alho Date: Mon, 4 Dec 2017 10:27:34 +0000 Subject: [PATCH 07/10] Remove FileVersion and Version elements to allow build to define the version --- src/Serilog.Sinks.Loggly/Serilog.Sinks.Loggly.csproj | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Serilog.Sinks.Loggly/Serilog.Sinks.Loggly.csproj b/src/Serilog.Sinks.Loggly/Serilog.Sinks.Loggly.csproj index bcc2730..c2f3c1d 100644 --- a/src/Serilog.Sinks.Loggly/Serilog.Sinks.Loggly.csproj +++ b/src/Serilog.Sinks.Loggly/Serilog.Sinks.Loggly.csproj @@ -16,8 +16,6 @@ http://www.apache.org/licenses/LICENSE-2.0 false Serilog - 5.2.0.0 - 5.2.0 From c02872d804df36c4186f9c1dd0b4ae36f92bd572 Mon Sep 17 00:00:00 2001 From: Miguel Alho Date: Mon, 15 Jan 2018 17:29:40 +0000 Subject: [PATCH 08/10] check for null bookmark before updating bookmark This has been found to occur if a program only generates a message(s) of a level that is not sent to the remote server (such as debug messages when the info level is the minimum). In this case, the bookmark file will exist on disk but be empty, and no messages will have been persisted on disk. The periodic check will fail in the UpdateBookmark call since no bookmark exists (null) --- .../Sinks/Loggly/FileBufferDataProvider.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Loggly/Sinks/Loggly/FileBufferDataProvider.cs b/src/Serilog.Sinks.Loggly/Sinks/Loggly/FileBufferDataProvider.cs index 8a5f39a..810b153 100644 --- a/src/Serilog.Sinks.Loggly/Sinks/Loggly/FileBufferDataProvider.cs +++ b/src/Serilog.Sinks.Loggly/Sinks/Loggly/FileBufferDataProvider.cs @@ -174,7 +174,11 @@ public void MoveBookmarkForward() //even if reading / deleteing files fails, we can / should update the bookmark file //it is important that the file have the reset position, otherwise we risk failing to // move forward in the next read cycle - _bookmarkProvider.UpdateBookmark(_currentBookmark); + //it's possible that no bookmark exists, especially if no valid messages have forced a + // durable log file to be created. In this case, the bookmark file will be empty and + // on disk + if(_currentBookmark != null) + _bookmarkProvider.UpdateBookmark(_currentBookmark); } } From b9ca2666100c2d007c0fb7dba5f9fc932ed5fe3b Mon Sep 17 00:00:00 2001 From: Miguel Alho Date: Tue, 16 Jan 2018 11:50:06 +0000 Subject: [PATCH 09/10] add minor xunit related fixes Assert.Equal is not recommended to check the size collection so that has changes to Assert.Single. Added a System.Core ref in the net452 test run context to avoid failures in tests (runner was trying to load System.Core to access the exception.StackTrace property) Added netcoreapp2.0 target in the test project to run in that context (and check if the System.Core ref was required in it). --- .../Serilog.Sinks.Loggly.Tests.csproj | 9 ++++++--- .../Sinks/Loggly/FileBufferDataProviderTests.cs | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/test/Serilog.Sinks.Loggly.Tests/Serilog.Sinks.Loggly.Tests.csproj b/test/Serilog.Sinks.Loggly.Tests/Serilog.Sinks.Loggly.Tests.csproj index 7cd58f0..d0cd6b3 100644 --- a/test/Serilog.Sinks.Loggly.Tests/Serilog.Sinks.Loggly.Tests.csproj +++ b/test/Serilog.Sinks.Loggly.Tests/Serilog.Sinks.Loggly.Tests.csproj @@ -1,7 +1,7 @@  - net452;netcoreapp1.0 + net452;netcoreapp1.0;netcoreapp2.0 Serilog.Sinks.Loggly.Tests ../../assets/Serilog.snk true @@ -33,15 +33,18 @@ - + - + + + + diff --git a/test/Serilog.Sinks.Loggly.Tests/Sinks/Loggly/FileBufferDataProviderTests.cs b/test/Serilog.Sinks.Loggly.Tests/Sinks/Loggly/FileBufferDataProviderTests.cs index aee61ee..20f6788 100644 --- a/test/Serilog.Sinks.Loggly.Tests/Sinks/Loggly/FileBufferDataProviderTests.cs +++ b/test/Serilog.Sinks.Loggly.Tests/Sinks/Loggly/FileBufferDataProviderTests.cs @@ -583,7 +583,7 @@ public void PreviousFileShouldHaveBeenDeleted() => [Fact] public void SingleFileShouldHaveBeenDeleted() => - Assert.Equal(1, _deletedFiles.Count); + Assert.Single(_deletedFiles); } public class RetentionLimitLessThenLimitNumberOfBufferFiles From 6b4501c7f47675e706523edf68be6238eb278186 Mon Sep 17 00:00:00 2001 From: Morten Brix Pedersen Date: Tue, 19 Jun 2018 11:02:06 +0200 Subject: [PATCH 10/10] Upgrade loggly-csharp dependency --- sample/sampleDurableLogger/sampleDurableLogger.csproj | 2 +- src/Serilog.Sinks.Loggly/Serilog.Sinks.Loggly.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sample/sampleDurableLogger/sampleDurableLogger.csproj b/sample/sampleDurableLogger/sampleDurableLogger.csproj index 064f9bb..713002c 100644 --- a/sample/sampleDurableLogger/sampleDurableLogger.csproj +++ b/sample/sampleDurableLogger/sampleDurableLogger.csproj @@ -17,7 +17,7 @@ - + diff --git a/src/Serilog.Sinks.Loggly/Serilog.Sinks.Loggly.csproj b/src/Serilog.Sinks.Loggly/Serilog.Sinks.Loggly.csproj index c2f3c1d..c78deda 100644 --- a/src/Serilog.Sinks.Loggly/Serilog.Sinks.Loggly.csproj +++ b/src/Serilog.Sinks.Loggly/Serilog.Sinks.Loggly.csproj @@ -19,7 +19,7 @@ - +