From 53885755752e342b1cbc95902c5b49a57510b612 Mon Sep 17 00:00:00 2001 From: Miguel Alho Date: Mon, 23 Dec 2019 15:12:56 +0000 Subject: [PATCH] Features/package upgrades (#51) * upgrade loggly-csharp and align system.net.http * clean up some compiler warnings Mainly code that can be made local and comments with semicolons considered code. * upgrade package with minor version changes * upgrade File sink (major version upgrade). Adds NetCore 3.1 as a test target * upgrade appveyor image to vs 2019 * add netcore3.1 in test project Microsoft.NET.Test.Sdk Version="16.2.0" is the last version that will support netcoreapp1.0 (most recent packages will not run the netcoreapp tests). * readded system.Core reference in test project Some test will not run without it in netcoreapp 1.0 * upgrade Nsubstitute package in test project * add ForwardedForIp example in sample project * add push property and ForwardForIP code in sample project --- appveyor.yml | 2 +- sample/sampleDurableLogger/Program.cs | 14 +++++++++++++- .../sampleDurableLogger.csproj | 16 +++++++--------- .../Serilog.Sinks.Loggly.csproj | 13 ++++++------- .../Sinks/Loggly/FileBufferDataProvider.cs | 4 ++-- .../Sinks/Loggly/HttpLogShipper.cs | 9 +++------ .../Serilog.Sinks.Loggly.Tests.csproj | 18 ++++++++++-------- 7 files changed, 42 insertions(+), 34 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 60dbfb3..6cd6faa 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,6 @@ version: '{build}' skip_tags: true -image: Visual Studio 2017 +image: Visual Studio 2019 configuration: Release init: - git config --global core.autocrlf false diff --git a/sample/sampleDurableLogger/Program.cs b/sample/sampleDurableLogger/Program.cs index 9c88943..d170fe6 100644 --- a/sample/sampleDurableLogger/Program.cs +++ b/sample/sampleDurableLogger/Program.cs @@ -1,8 +1,10 @@ using System; using System.Globalization; +using System.Runtime.InteropServices; using Loggly; using Loggly.Config; using Serilog; +using Serilog.Context; using Serilog.Core; using Serilog.Core.Enrichers; using Serilog.Enrichers; @@ -37,7 +39,15 @@ public static void Main() logger.Warning("Third test message with {@Data}", new {P1 = "sample3", P2 = DateTime.Now}); Console.WriteLine( - "Back online messages written. Check loggly and files for data. Wait a minute or so before reconnecting. Press Enter to terminate"); + "Back online messages written. Check loggly and files for data. Wait a minute or so before reconnecting. Press Enter to continue"); + Console.ReadLine(); + + using (LogContext.PushProperty("sampleProperty", "Sample Value")) + { + logger.Information("message to send with {@Data}", new { P1 = "sample4", P2 = DateTime.Now }); + } + Console.WriteLine( + "Pushed property added to object. Check loggly and data. Press Enter to terminate"); Console.ReadLine(); } } @@ -92,6 +102,8 @@ static void SetupLogglyConfiguration() LogTransport = LogTransport.Https }; config.ThrowExceptions = true; + //use the new Transport property that hides IP as of loggly-csharp 4.6.1.76 + config.Transport.ForwardedForIp = "0.0.0.0"; //Define Tags sent to Loggly config.TagConfig.Tags.AddRange(new ITag[]{ diff --git a/sample/sampleDurableLogger/sampleDurableLogger.csproj b/sample/sampleDurableLogger/sampleDurableLogger.csproj index 713002c..fdd1a81 100644 --- a/sample/sampleDurableLogger/sampleDurableLogger.csproj +++ b/sample/sampleDurableLogger/sampleDurableLogger.csproj @@ -4,9 +4,7 @@ netcoreapp1.0 sampleDurableLogger Exe - sampleDurableLogger 1.0.4 - $(PackageTargetFallback);dnxcore50 false false false @@ -17,17 +15,17 @@ - + - - - + + + - - + + - + diff --git a/src/Serilog.Sinks.Loggly/Serilog.Sinks.Loggly.csproj b/src/Serilog.Sinks.Loggly/Serilog.Sinks.Loggly.csproj index d4a6eb6..16174ac 100644 --- a/src/Serilog.Sinks.Loggly/Serilog.Sinks.Loggly.csproj +++ b/src/Serilog.Sinks.Loggly/Serilog.Sinks.Loggly.csproj @@ -21,16 +21,15 @@ - + - - - + + + - @@ -40,8 +39,8 @@ - - + + diff --git a/src/Serilog.Sinks.Loggly/Sinks/Loggly/FileBufferDataProvider.cs b/src/Serilog.Sinks.Loggly/Sinks/Loggly/FileBufferDataProvider.cs index 0370e06..977d820 100644 --- a/src/Serilog.Sinks.Loggly/Sinks/Loggly/FileBufferDataProvider.cs +++ b/src/Serilog.Sinks.Loggly/Sinks/Loggly/FileBufferDataProvider.cs @@ -195,7 +195,7 @@ public void MoveBookmarkForward() } //also clear all the previous files in the set to avoid problems (and because - //they should no longer be considered); If no previous exists (index is -1); + //they should no longer be considered). If no previous exists (index is -1) //keep existing; also do not reomve last file as it may be written to / locked DeleteFilesInFileSetUpToIndex(fileSet, currentBookMarkedFileInFileSet + 1); } @@ -384,7 +384,7 @@ LogglyEvent DeserializeEvent(string eventLine) FileSetPosition TryGetValidBookmark() { - //get from the bookmark file first; + //get from the bookmark file first FileSetPosition newBookmark = _bookmarkProvider.GetCurrentBookmarkPosition(); if (!IsValidBookmark(newBookmark)) diff --git a/src/Serilog.Sinks.Loggly/Sinks/Loggly/HttpLogShipper.cs b/src/Serilog.Sinks.Loggly/Sinks/Loggly/HttpLogShipper.cs index 01b82dc..2cdb70f 100644 --- a/src/Serilog.Sinks.Loggly/Sinks/Loggly/HttpLogShipper.cs +++ b/src/Serilog.Sinks.Loggly/Sinks/Loggly/HttpLogShipper.cs @@ -31,7 +31,6 @@ namespace Serilog.Sinks.Loggly class HttpLogShipper : IDisposable { readonly int _batchPostingLimit; - private readonly int? _retainedFileCountLimit; readonly ExponentialBackoffConnectionSchedule _connectionSchedule; readonly object _stateLock = new object(); @@ -43,7 +42,6 @@ class HttpLogShipper : IDisposable readonly IFileSystemAdapter _fileSystemAdapter = new FileSystemAdapter(); readonly FileBufferDataProvider _bufferDataProvider; readonly InvalidPayloadLogger _invalidPayloadLogger; - readonly LogglyConfigAdapter _adapter; public HttpLogShipper( string bufferBaseFilename, @@ -57,15 +55,14 @@ public HttpLogShipper( LogglyConfiguration logglyConfiguration) { _batchPostingLimit = batchPostingLimit; - _retainedFileCountLimit = retainedFileCountLimit; - + _controlledSwitch = new ControlledLevelSwitch(levelControlSwitch); _connectionSchedule = new ExponentialBackoffConnectionSchedule(period); if (logglyConfiguration != null) { - _adapter = new LogglyConfigAdapter(); - _adapter.ConfigureLogglyClient(logglyConfiguration); + var adapter = new LogglyConfigAdapter(); + adapter.ConfigureLogglyClient(logglyConfiguration); } _logglyClient = new LogglyClient(); //we'll use the loggly client instead of HTTP directly 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 d0cd6b3..441ec5b 100644 --- a/test/Serilog.Sinks.Loggly.Tests/Serilog.Sinks.Loggly.Tests.csproj +++ b/test/Serilog.Sinks.Loggly.Tests/Serilog.Sinks.Loggly.Tests.csproj @@ -1,15 +1,14 @@  - net452;netcoreapp1.0;netcoreapp2.0 + net452;netcoreapp1.0;netcoreapp2.1;netcoreapp3.1 Serilog.Sinks.Loggly.Tests ../../assets/Serilog.snk true true Serilog.Sinks.Loggly.Tests true - $(PackageTargetFallback);portable-net45+win8 - 1.0.4 + true @@ -31,11 +30,14 @@ - - - - - + + + + + all + runtime; build; native; contentfiles; analyzers + +