From 7d45dafbf9bb1cbad10aaaa23b84d9cd3898d5ae Mon Sep 17 00:00:00 2001 From: Matthew Erbs Date: Thu, 18 May 2017 03:11:23 +1000 Subject: [PATCH 01/13] Convert to VS2017 tooling --- Build.ps1 | 24 ++++++---- global.json | 6 --- serilog-sinks-splunk.sln | 21 ++------ .../Serilog.Sinks.Splunk.csproj | 41 ++++++++++++++++ .../Serilog.Sinks.Splunk.xproj | 18 ------- src/Serilog.Sinks.Splunk/project.json | 48 ------------------- .../Serilog.Sinks.Splunk.Tests.csproj | 28 +++++++++++ .../Serilog.Sinks.Splunk.Tests.xproj | 18 ------- test/Serilog.Sinks.Splunk.Tests/project.json | 24 ---------- 9 files changed, 88 insertions(+), 140 deletions(-) delete mode 100644 global.json create mode 100644 src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj delete mode 100644 src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.xproj delete mode 100644 src/Serilog.Sinks.Splunk/project.json create mode 100644 test/Serilog.Sinks.Splunk.Tests/Serilog.Sinks.Splunk.Tests.csproj delete mode 100644 test/Serilog.Sinks.Splunk.Tests/Serilog.Sinks.Splunk.Tests.xproj delete mode 100644 test/Serilog.Sinks.Splunk.Tests/project.json diff --git a/Build.ps1 b/Build.ps1 index 7c5a85f..648b068 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -12,38 +12,42 @@ if(Test-Path .\artifacts) { $branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL]; $revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; $suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"] +$commitHash = $(git rev-parse --short HEAD) +$buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""] -echo "build: Version suffix is $suffix" +echo "build: Package version suffix is $suffix" +echo "build: Build version suffix is $buildSuffix" foreach ($src in ls src/*) { Push-Location $src echo "build: Packaging project in $src" - & dotnet pack -c Release -o ..\..\artifacts --version-suffix=$suffix + & dotnet build -c Release --version-suffix=$buildSuffix + & dotnet pack -c Release --include-symbols -o ..\..\artifacts --version-suffix=$suffix --no-build if($LASTEXITCODE -ne 0) { exit 1 } Pop-Location } -foreach ($test in ls test/*.PerformanceTests) { +foreach ($test in ls test/*.Tests) { Push-Location $test - echo "build: Building performance test project in $test" + echo "build: Testing project in $test" - & dotnet build -c Release - if($LASTEXITCODE -ne 0) { exit 2 } + & dotnet test -c Release + if($LASTEXITCODE -ne 0) { exit 3 } Pop-Location } -foreach ($test in ls test/*.Tests) { +foreach ($test in ls test/*.PerformanceTests) { Push-Location $test - echo "build: Testing project in $test" + echo "build: Building performance test project in $test" - & dotnet test -c Release - if($LASTEXITCODE -ne 0) { exit 3 } + & dotnet build -c Release + if($LASTEXITCODE -ne 0) { exit 2 } Pop-Location } diff --git a/global.json b/global.json deleted file mode 100644 index a2b2a41..0000000 --- a/global.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "projects": [ "src", "test" ], - "sdk": { - "version": "1.0.0-preview2-003121" - } -} diff --git a/serilog-sinks-splunk.sln b/serilog-sinks-splunk.sln index ae40934..5f8cb17 100644 --- a/serilog-sinks-splunk.sln +++ b/serilog-sinks-splunk.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 +# Visual Studio 15 +VisualStudioVersion = 15.0.26430.6 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{7A774CBB-A6E9-4854-B4DB-4CF860B0C1C5}" EndProject @@ -9,25 +9,19 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{B9B133 ProjectSection(SolutionItems) = preProject Build.ps1 = Build.ps1 CHANGES.md = CHANGES.md - global.json = global.json README.md = README.md assets\Serilog.snk = assets\Serilog.snk EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{B16AD407-36C8-4286-A3E9-CACEBF359731}" - ProjectSection(SolutionItems) = preProject - .nuget\packages.config = .nuget\packages.config - EndProjectSection -EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.Splunk", "src\Serilog.Sinks.Splunk\Serilog.Sinks.Splunk.xproj", "{32CF915C-3ECD-496C-8FDB-1214581274A6}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{1C75E4A9-4CB1-497C-AD17-B438882051A1}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Sample", "src\sample\Sample.xproj", "{17497155-5D94-45DF-81D9-BD960E8CF217}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{B9451AD8-09B9-4C09-A152-FBAE24806614}" EndProject -Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Serilog.Sinks.Splunk.Tests", "test\Serilog.Sinks.Splunk.Tests\Serilog.Sinks.Splunk.Tests.xproj", "{3C2D8E01-5580-426A-BDD9-EC59CD98E618}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Sinks.Splunk", "src\Serilog.Sinks.Splunk\Serilog.Sinks.Splunk.csproj", "{32CF915C-3ECD-496C-8FDB-1214581274A6}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Sinks.Splunk.Tests", "test\Serilog.Sinks.Splunk.Tests\Serilog.Sinks.Splunk.Tests.csproj", "{3C2D8E01-5580-426A-BDD9-EC59CD98E618}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,10 +33,6 @@ Global {32CF915C-3ECD-496C-8FDB-1214581274A6}.Debug|Any CPU.Build.0 = Debug|Any CPU {32CF915C-3ECD-496C-8FDB-1214581274A6}.Release|Any CPU.ActiveCfg = Release|Any CPU {32CF915C-3ECD-496C-8FDB-1214581274A6}.Release|Any CPU.Build.0 = Release|Any CPU - {17497155-5D94-45DF-81D9-BD960E8CF217}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {17497155-5D94-45DF-81D9-BD960E8CF217}.Debug|Any CPU.Build.0 = Debug|Any CPU - {17497155-5D94-45DF-81D9-BD960E8CF217}.Release|Any CPU.ActiveCfg = Release|Any CPU - {17497155-5D94-45DF-81D9-BD960E8CF217}.Release|Any CPU.Build.0 = Release|Any CPU {3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Debug|Any CPU.Build.0 = Debug|Any CPU {3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -53,7 +43,6 @@ Global EndGlobalSection GlobalSection(NestedProjects) = preSolution {32CF915C-3ECD-496C-8FDB-1214581274A6} = {7A774CBB-A6E9-4854-B4DB-4CF860B0C1C5} - {17497155-5D94-45DF-81D9-BD960E8CF217} = {1C75E4A9-4CB1-497C-AD17-B438882051A1} {3C2D8E01-5580-426A-BDD9-EC59CD98E618} = {B9451AD8-09B9-4C09-A152-FBAE24806614} EndGlobalSection EndGlobal diff --git a/src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj b/src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj new file mode 100644 index 0000000..52b6b5d --- /dev/null +++ b/src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj @@ -0,0 +1,41 @@ + + + + The Splunk Sink for Serilog + 2.1.3 + Matthew Erbs, Serilog Contributors + net45;netstandard1.1 + true + Serilog.Sinks.Splunk + Serilog.Sinks.Splunk + serilog;splunk;logging;event;collector + http://serilog.net/images/serilog-sink-nuget.png + https://github.com/serilog/serilog-sinks-splunk + http://www.apache.org/licenses/LICENSE-2.0 + false + + + + + + + + + + + + + + + $(DefineConstants);TCP;UDP + + + + + + + + + + + diff --git a/src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.xproj b/src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.xproj deleted file mode 100644 index 5ebac95..0000000 --- a/src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.xproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 32cf915c-3ecd-496c-8fdb-1214581274a6 - Serilog - .\obj - .\bin\ - - - 2.0 - - - \ No newline at end of file diff --git a/src/Serilog.Sinks.Splunk/project.json b/src/Serilog.Sinks.Splunk/project.json deleted file mode 100644 index e178e33..0000000 --- a/src/Serilog.Sinks.Splunk/project.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "version": "2.1.3-*", - "description": "The Splunk Sink for Serilog", - "authors": [ - "Matthew Erbs, Serilog Contributors" - ], - "packOptions": { - "tags": [ - "serilog", - "splunk", - "logging", - "event", - "collector" - ], - "projectUrl": "https://github.com/serilog/serilog-sinks-splunk", - "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0", - "iconUrl": "http://serilog.net/images/serilog-sink-nuget.png" - }, - "buildOptions": { - - "xmlDoc": true - }, - "dependencies": { - "Serilog": "2.2.0" - }, - "frameworks": { - "net4.5": { - "buildOptions": { - "define": [ "TCP", "UDP" ] - }, - "frameworkAssemblies": { - "System.Net.Http": "" - }, - "dependencies": { - "Splunk.Logging.Common": "1.6.0" - } - }, - "netstandard1.1": { - "dependencies": { - "System.Collections": "4.0.11", - "System.Collections.Concurrent": "4.0.12", - "System.Runtime": "4.1.0", - "System.Threading": "4.0.11", - "System.Net.Http": "4.1.0" - } - } - } -} diff --git a/test/Serilog.Sinks.Splunk.Tests/Serilog.Sinks.Splunk.Tests.csproj b/test/Serilog.Sinks.Splunk.Tests/Serilog.Sinks.Splunk.Tests.csproj new file mode 100644 index 0000000..5ec489a --- /dev/null +++ b/test/Serilog.Sinks.Splunk.Tests/Serilog.Sinks.Splunk.Tests.csproj @@ -0,0 +1,28 @@ + + + + net452;netcoreapp1.0 + Serilog.Sinks.Splunk.Tests + Serilog.Sinks.Splunk.Tests + true + $(PackageTargetFallback);dnxcore50;portable-net45+win8 + 1.0.4 + + + + + + + + + + + + + + + + + + + diff --git a/test/Serilog.Sinks.Splunk.Tests/Serilog.Sinks.Splunk.Tests.xproj b/test/Serilog.Sinks.Splunk.Tests/Serilog.Sinks.Splunk.Tests.xproj deleted file mode 100644 index e1971a9..0000000 --- a/test/Serilog.Sinks.Splunk.Tests/Serilog.Sinks.Splunk.Tests.xproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 3c2d8e01-5580-426a-bdd9-ec59cd98e618 - Serilog.Sinks.Splunk.Tests - .\obj - .\bin\ - - - 2.0 - - - \ No newline at end of file diff --git a/test/Serilog.Sinks.Splunk.Tests/project.json b/test/Serilog.Sinks.Splunk.Tests/project.json deleted file mode 100644 index 1d6c4dc..0000000 --- a/test/Serilog.Sinks.Splunk.Tests/project.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "testRunner": "xunit", - "dependencies": { - "Serilog.Sinks.Splunk": { "target": "project" }, - "xunit": "2.1.0", - "dotnet-test-xunit": "1.0.0-rc2-build10025", - "Newtonsoft.Json": "8.0.3" - }, - "frameworks": { - "net4.5.2": { }, - "netcoreapp1.0": { - "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.0" - } - }, - "imports": [ - "dnxcore50", - "portable-net45+win8" - ] - } - } -} From cf4f6b8757c948756656d9d1006c38e53078fa5e Mon Sep 17 00:00:00 2001 From: Matthew Erbs Date: Sat, 20 May 2017 08:07:05 +1000 Subject: [PATCH 02/13] Added sample and removed old files. Version bump --- CHANGES.md | 3 + sample/{ => Sample}/Program.cs | 59 +++++++++---------- sample/Sample/Sample.csproj | 17 ++++++ sample/project.json | 19 ------ serilog-sinks-splunk.sln | 8 +++ .../Serilog.Sinks.Splunk.csproj | 9 +-- 6 files changed, 60 insertions(+), 55 deletions(-) rename sample/{ => Sample}/Program.cs (86%) mode change 100755 => 100644 create mode 100644 sample/Sample/Sample.csproj delete mode 100755 sample/project.json diff --git a/CHANGES.md b/CHANGES.md index d2b9fb9..2d917bb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,6 @@ +##2.2.0 +- [#47] Tooling updates to VS2017 + ##2.1.2 - [#43](https://github.com/serilog/serilog-sinks-splunk/pull/43) - Extend sink & static configuration to allow for custom JSON formatter. diff --git a/sample/Program.cs b/sample/Sample/Program.cs old mode 100755 new mode 100644 similarity index 86% rename from sample/Program.cs rename to sample/Sample/Program.cs index 7ec94b7..5cc145c --- a/sample/Program.cs +++ b/sample/Sample/Program.cs @@ -1,27 +1,22 @@ using System.Linq; -using System.Threading; using Serilog; -using Serilog.Core; namespace Sample { - /// - /// Sample 10 false - /// public class Program { public static string EventCollectorToken = "2B94855F-1184-46F7-BFF1-56A3112F627E"; - + public static void Main(string[] args) { var eventsToCreate = 100; var runSSL = false; - - if(args.Length > 0) - eventsToCreate = int.Parse(args[0]); - - if(args.Length == 2) - runSSL = bool.Parse(args[1]); + + if (args.Length > 0) + eventsToCreate = int.Parse(args[0]); + + if (args.Length == 2) + runSSL = bool.Parse(args[1]); Log.Information("Sample starting up"); Serilog.Debugging.SelfLog.Enable(System.Console.Out); @@ -33,9 +28,9 @@ public static void Main(string[] args) OverridingHost(eventsToCreate); WithNoTemplate(eventsToCreate); - if(runSSL) + if (runSSL) UsingSSL(eventsToCreate); - + Log.Debug("Done"); } @@ -44,15 +39,15 @@ public static void OverridingSource(int eventsToCreate) // Override Source Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() - .WriteTo.LiterateConsole() + .WriteTo.LiterateConsole() .WriteTo.EventCollector( - "http://localhost:8088", + "http://localhost:8088", Program.EventCollectorToken, source: "Serilog.Sinks.Splunk.Sample.TestSource") .Enrich.WithProperty("Serilog.Sinks.Splunk.Sample", "ViaEventCollector") .Enrich.WithProperty("Serilog.Sinks.Splunk.Sample.TestType", "Source Override") .CreateLogger(); - + foreach (var i in Enumerable.Range(0, eventsToCreate)) { Log.Information("Running source override loop {Counter}", i); @@ -67,15 +62,15 @@ public static void OverridingSourceType(int eventsToCreate) // Override Source Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() - .WriteTo.LiterateConsole() + .WriteTo.LiterateConsole() .WriteTo.EventCollector( - "http://localhost:8088", + "http://localhost:8088", Program.EventCollectorToken, sourceType: "Serilog.Sinks.Splunk.Sample.TestSourceType") .Enrich.WithProperty("Serilog.Sinks.Splunk.Sample", "ViaEventCollector") .Enrich.WithProperty("Serilog.Sinks.Splunk.Sample.TestType", "Source Type Override") .CreateLogger(); - + foreach (var i in Enumerable.Range(0, eventsToCreate)) { Log.Information("Running source type override loop {Counter}", i); @@ -90,15 +85,15 @@ public static void OverridingHost(int eventsToCreate) // Override Host Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() - .WriteTo.LiterateConsole() + .WriteTo.LiterateConsole() .WriteTo.EventCollector( - "http://localhost:8088", + "http://localhost:8088", Program.EventCollectorToken, host: "myamazingmachine") .Enrich.WithProperty("Serilog.Sinks.Splunk.Sample", "ViaEventCollector") .Enrich.WithProperty("Serilog.Sinks.Splunk.Sample.TestType", "Host Override") .CreateLogger(); - + foreach (var i in Enumerable.Range(0, eventsToCreate)) { Log.Information("Running host override loop {Counter}", i); @@ -113,7 +108,7 @@ public static void UsingFullUri(int eventsToCreate) // Vanilla Test with full uri specified Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() - .WriteTo.LiterateConsole() + .WriteTo.LiterateConsole() .WriteTo.EventCollector( "http://localhost:8088/services/collector", Program.EventCollectorToken) @@ -135,13 +130,13 @@ public static void UsingHostOnly(int eventsToCreate) // Vanilla Tests just host Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() - .WriteTo.LiterateConsole() + .WriteTo.LiterateConsole() .WriteTo.EventCollector( "http://localhost:8088", Program.EventCollectorToken) .Enrich.WithProperty("Serilog.Sinks.Splunk.Sample", "ViaEventCollector") .Enrich.WithProperty("Serilog.Sinks.Splunk.Sample.TestType", "Vanilla No services/collector in uri") - .CreateLogger(); + .CreateLogger(); foreach (var i in Enumerable.Range(0, eventsToCreate)) { @@ -156,15 +151,15 @@ public static void WithNoTemplate(int eventsToCreate) // No Template Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() - .WriteTo.LiterateConsole() + .WriteTo.LiterateConsole() .WriteTo.EventCollector( - "http://localhost:8088", + "http://localhost:8088", Program.EventCollectorToken, renderTemplate: false) .Enrich.WithProperty("Serilog.Sinks.Splunk.Sample", "ViaEventCollector") .Enrich.WithProperty("Serilog.Sinks.Splunk.Sample.TestType", "No Templates") .CreateLogger(); - + foreach (var i in Enumerable.Range(0, eventsToCreate)) { Log.Information("Running no template loop {Counter}", i); @@ -178,14 +173,14 @@ public static void UsingSSL(int eventsToCreate) // SSL Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() - .WriteTo.LiterateConsole() + .WriteTo.LiterateConsole() .WriteTo.EventCollector( "https://localhost:8088", Program.EventCollectorToken) .Enrich.WithProperty("Serilog.Sinks.Splunk.Sample", "ViaEventCollector") .Enrich.WithProperty("Serilog.Sinks.Splunk.Sample.TestType", "HTTPS") - .CreateLogger(); - + .CreateLogger(); + foreach (var i in Enumerable.Range(0, eventsToCreate)) { Log.Information("HTTPS {Counter}", i); diff --git a/sample/Sample/Sample.csproj b/sample/Sample/Sample.csproj new file mode 100644 index 0000000..ea50423 --- /dev/null +++ b/sample/Sample/Sample.csproj @@ -0,0 +1,17 @@ + + + + Exe + netcoreapp1.0 + + + + + + + + + + + + \ No newline at end of file diff --git a/sample/project.json b/sample/project.json deleted file mode 100755 index 444bc25..0000000 --- a/sample/project.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "version": "2.1.3", - "buildOptions": { - "emitEntryPoint": true - }, - "dependencies": { - "Microsoft.NETCore.App": { - "type": "platform", - "version": "1.0.0" - }, - "Serilog.Sinks.Splunk": {"target": "project"}, - "Serilog.Sinks.Literate": "2.0.0" - }, - "frameworks": { - "netcoreapp1.0": { - "imports": "dnxcore50" - } - } -} diff --git a/serilog-sinks-splunk.sln b/serilog-sinks-splunk.sln index 5f8cb17..703f61f 100644 --- a/serilog-sinks-splunk.sln +++ b/serilog-sinks-splunk.sln @@ -8,6 +8,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{B9B13339-749C-4098-8845-780ED4FA488A}" ProjectSection(SolutionItems) = preProject Build.ps1 = Build.ps1 + build.sh = build.sh CHANGES.md = CHANGES.md README.md = README.md assets\Serilog.snk = assets\Serilog.snk @@ -23,6 +24,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Sinks.Splunk", "src EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Sinks.Splunk.Tests", "test\Serilog.Sinks.Splunk.Tests\Serilog.Sinks.Splunk.Tests.csproj", "{3C2D8E01-5580-426A-BDD9-EC59CD98E618}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample", "sample\Sample\Sample.csproj", "{4A4E361D-8BBE-4DDD-9E6C-53960C2B5F5B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -37,6 +40,10 @@ Global {3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Debug|Any CPU.Build.0 = Debug|Any CPU {3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Release|Any CPU.ActiveCfg = Release|Any CPU {3C2D8E01-5580-426A-BDD9-EC59CD98E618}.Release|Any CPU.Build.0 = Release|Any CPU + {4A4E361D-8BBE-4DDD-9E6C-53960C2B5F5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4A4E361D-8BBE-4DDD-9E6C-53960C2B5F5B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4A4E361D-8BBE-4DDD-9E6C-53960C2B5F5B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4A4E361D-8BBE-4DDD-9E6C-53960C2B5F5B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -44,5 +51,6 @@ Global GlobalSection(NestedProjects) = preSolution {32CF915C-3ECD-496C-8FDB-1214581274A6} = {7A774CBB-A6E9-4854-B4DB-4CF860B0C1C5} {3C2D8E01-5580-426A-BDD9-EC59CD98E618} = {B9451AD8-09B9-4C09-A152-FBAE24806614} + {4A4E361D-8BBE-4DDD-9E6C-53960C2B5F5B} = {1C75E4A9-4CB1-497C-AD17-B438882051A1} EndGlobalSection EndGlobal diff --git a/src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj b/src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj index 52b6b5d..547174d 100644 --- a/src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj +++ b/src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj @@ -13,12 +13,9 @@ https://github.com/serilog/serilog-sinks-splunk http://www.apache.org/licenses/LICENSE-2.0 false + 2.2.0 - - - - @@ -38,4 +35,8 @@ + + + + From 1652983fcda82decc80d00a255e3b4aaeabea749 Mon Sep 17 00:00:00 2001 From: Matthew Erbs Date: Sat, 20 May 2017 08:45:50 +1000 Subject: [PATCH 03/13] Build def changes for VS2017 tooling --- .travis.yml | 49 +++++++++---------------------------------------- appveyor.yml | 6 +++--- 2 files changed, 12 insertions(+), 43 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4a81e54..813887d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,46 +1,15 @@ language: csharp -#dotnet cli require Ubuntu 14.04 -sudo: required -dist: trusty - -#dotnet cli require OSX 10.10 -osx_image: xcode7.1 - -addons: - apt: - packages: - - gettext - - libcurl4-openssl-dev - - libicu-dev - - libssl-dev - - libunwind8 - - zlib1g - -os: - #- osx - - linux - -env: - matrix: - - CLI_VERSION=1.0.0-preview2-003121 - # - CLI_VERSION=Latest - matrix: - allow_failures: - - env: CLI_VERSION=Latest - -before_install: - - if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl; brew link --force openssl; fi - # Download script to install dotnet cli - - if test "$CLI_OBTAIN_URL" == ""; then export CLI_OBTAIN_URL="https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview2/scripts/obtain/dotnet-install.sh"; fi - - curl -L --create-dirs $CLI_OBTAIN_URL -o ./scripts/obtain/install.sh - - find ./scripts -name "*.sh" -exec chmod +x {} \; - - export DOTNET_INSTALL_DIR="$PWD/.dotnetcli" - # use bash to workaround bug https://github.com/dotnet/cli/issues/1725 - - sudo bash ./scripts/obtain/install.sh --channel "preview" --version "$CLI_VERSION" --install-dir "$DOTNET_INSTALL_DIR" --no-path - # add dotnet to PATH - - export PATH="$DOTNET_INSTALL_DIR:$PATH" + include: + - os: linux # Ubuntu 14.04 + dist: trusty + sudo: required + dotnet: 1.0.1 + # Disabled temporarily due to Travis OSX issues + # - os: osx # OSX 10.11 + # osx_image: xcode7.3 + # dotnet: 1.0.1 script: - ./build.sh \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 19d0d28..d860077 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -4,9 +4,9 @@ image: Visual Studio 2015 configuration: Release install: - ps: mkdir -Force ".\build\" | Out-Null - - ps: Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0-preview2/scripts/obtain/dotnet-install.ps1" -OutFile ".\build\installcli.ps1" + - ps: Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/dotnet-install.ps1" -OutFile ".\build\installcli.ps1" - ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetcli" - - ps: '& .\build\installcli.ps1 -InstallDir "$env:DOTNET_INSTALL_DIR" -NoPath -Version 1.0.0-preview2-003121' + - ps: '& .\build\installcli.ps1 -InstallDir "$env:DOTNET_INSTALL_DIR" -NoPath -Version 1.0.1' - ps: $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path" build_script: - ps: ./Build.ps1 @@ -26,4 +26,4 @@ deploy: artifact: /Serilog.*\.nupkg/ tag: v$(appveyor_build_version) on: - branch: master + branch: master \ No newline at end of file From c81403085c18443d7518b2ce23f3be033843bafe Mon Sep 17 00:00:00 2001 From: Matthew Erbs Date: Sat, 20 May 2017 09:42:09 +1000 Subject: [PATCH 04/13] Correcting build issues on Travis --- .travis.yml | 4 ---- build.sh | 35 ++++++++++++++++++++--------------- serilog-sinks-splunk.sln | 2 ++ 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index 813887d..e446d88 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,10 +6,6 @@ matrix: dist: trusty sudo: required dotnet: 1.0.1 - # Disabled temporarily due to Travis OSX issues - # - os: osx # OSX 10.11 - # osx_image: xcode7.3 - # dotnet: 1.0.1 script: - ./build.sh \ No newline at end of file diff --git a/build.sh b/build.sh index 308817a..26762be 100755 --- a/build.sh +++ b/build.sh @@ -1,21 +1,26 @@ #!/bin/bash -# Ensure any exit code exits TravisCI -set -e +set -e +export DOTNET_INSTALL_DIR="$PWD/.dotnetcli" +DotnetCliVersion=${CLI_VERSION:="1.0.1"} +install_script_url=https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/dotnet-install.sh +curl -sSL $install_script_url | bash /dev/stdin --version "$DotnetCliVersion" --install-dir "$DOTNET_INSTALL_DIR" +export PATH="$DOTNET_INSTALL_DIR:$PATH" + +# See issue https://github.com/NuGet/Home/issues/2163 +ulimit -n 2048 + +dotnet --info dotnet restore -for path in src/*/project.json; do - dirname="$(dirname "${path}")" - dotnet build ${dirname} -done -for path in sample/project.json; do - dirname="$(dirname "${path}")" - dotnet build ${dirname} -done +for path in src/**/*.csproj; do + dotnet build -f netstandard1.0 -c Release ${path} + dotnet build -f netstandard1.3 -c Release ${path} +done + +for path in test/*.Tests/*.csproj; do + dotnet test -f netcoreapp1.0 -c Release ${path} +done -for path in test/Serilog.Sinks.Splunk.Tests/project.json; do - dirname="$(dirname "${path}")" - dotnet build ${dirname} -f netcoreapp1.0 -c Release - dotnet test ${dirname} -f netcoreapp1.0 -c Release -done \ No newline at end of file +dotnet build -f netcoreapp1.0 -c Release sample/Sample.csproj \ No newline at end of file diff --git a/serilog-sinks-splunk.sln b/serilog-sinks-splunk.sln index 703f61f..059cd09 100644 --- a/serilog-sinks-splunk.sln +++ b/serilog-sinks-splunk.sln @@ -7,6 +7,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{7A774CBB-A6E EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{B9B13339-749C-4098-8845-780ED4FA488A}" ProjectSection(SolutionItems) = preProject + .travis.yml = .travis.yml + appveyor.yml = appveyor.yml Build.ps1 = Build.ps1 build.sh = build.sh CHANGES.md = CHANGES.md From 073df3393a14e2f40d787d7b6d9c7ce5701f6f6f Mon Sep 17 00:00:00 2001 From: Matthew Erbs Date: Sat, 20 May 2017 13:44:03 +1000 Subject: [PATCH 05/13] Changed to target netstandard 1.1. on travis --- .travis.yml | 2 +- Build.ps1 | 2 +- build.sh | 3 +-- .../Serilog.Sinks.Splunk.Tests.csproj | 8 ++++---- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index e446d88..ba8d764 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ matrix: - os: linux # Ubuntu 14.04 dist: trusty sudo: required - dotnet: 1.0.1 + dotnet: 1.0.4 script: - ./build.sh \ No newline at end of file diff --git a/Build.ps1 b/Build.ps1 index 648b068..1a93b9d 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -41,7 +41,7 @@ foreach ($test in ls test/*.Tests) { Pop-Location } -foreach ($test in ls test/*.PerformanceTests) { +foreach ($test in ls sample/Sample) { Push-Location $test echo "build: Building performance test project in $test" diff --git a/build.sh b/build.sh index 26762be..5c88170 100755 --- a/build.sh +++ b/build.sh @@ -15,8 +15,7 @@ dotnet --info dotnet restore for path in src/**/*.csproj; do - dotnet build -f netstandard1.0 -c Release ${path} - dotnet build -f netstandard1.3 -c Release ${path} + dotnet build -f netstandard1.1 -c Release ${path} done for path in test/*.Tests/*.csproj; do diff --git a/test/Serilog.Sinks.Splunk.Tests/Serilog.Sinks.Splunk.Tests.csproj b/test/Serilog.Sinks.Splunk.Tests/Serilog.Sinks.Splunk.Tests.csproj index 5ec489a..2e0bab0 100644 --- a/test/Serilog.Sinks.Splunk.Tests/Serilog.Sinks.Splunk.Tests.csproj +++ b/test/Serilog.Sinks.Splunk.Tests/Serilog.Sinks.Splunk.Tests.csproj @@ -14,10 +14,10 @@ - - - - + + + + From 9543441caeb62d8eb3ebe02ff8d26b1fbe3d6fc5 Mon Sep 17 00:00:00 2001 From: Matthew Erbs Date: Sat, 20 May 2017 13:53:57 +1000 Subject: [PATCH 06/13] Corrected path to new sample project --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 5c88170..a0260af 100755 --- a/build.sh +++ b/build.sh @@ -22,4 +22,4 @@ for path in test/*.Tests/*.csproj; do dotnet test -f netcoreapp1.0 -c Release ${path} done -dotnet build -f netcoreapp1.0 -c Release sample/Sample.csproj \ No newline at end of file +dotnet build -f netcoreapp1.0 -c Release sample/Sample/Sample.csproj \ No newline at end of file From 49a5651cb8a31673035503d2e30449b4d65c568b Mon Sep 17 00:00:00 2001 From: Matthew Erbs Date: Sat, 20 May 2017 15:13:32 +1000 Subject: [PATCH 07/13] Specific target of Sample and exit on error --- Build.ps1 | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/Build.ps1 b/Build.ps1 index 1a93b9d..0398317 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -1,3 +1,4 @@ +$ErrorActionPreference = "Stop" echo "build: Build started" Push-Location $PSScriptRoot @@ -41,15 +42,6 @@ foreach ($test in ls test/*.Tests) { Pop-Location } -foreach ($test in ls sample/Sample) { - Push-Location $test - - echo "build: Building performance test project in $test" - - & dotnet build -c Release - if($LASTEXITCODE -ne 0) { exit 2 } - - Pop-Location -} +dotnet build -c Release .\sample\Sample\Sample.csproj Pop-Location From 6518de7ab2bb5336d0ae9d49fbb44f05cad9edb9 Mon Sep 17 00:00:00 2001 From: Matthew Erbs Date: Sat, 20 May 2017 15:36:36 +1000 Subject: [PATCH 08/13] Added version suffix to csproj --- src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj b/src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj index 547174d..3af454a 100644 --- a/src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj +++ b/src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj @@ -13,7 +13,7 @@ https://github.com/serilog/serilog-sinks-splunk http://www.apache.org/licenses/LICENSE-2.0 false - 2.2.0 + 2.2.0$(VersionSuffix) From ef2eb431d94c2140c55a7cbca15118ce884f84bb Mon Sep 17 00:00:00 2001 From: Matthew Erbs Date: Sun, 21 May 2017 07:52:02 +1000 Subject: [PATCH 09/13] Added hypen for local and dev build --- Build.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Build.ps1 b/Build.ps1 index 0398317..18f09c5 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -12,7 +12,7 @@ if(Test-Path .\artifacts) { $branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL]; $revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; -$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"] +$suffix = @{ $true = ""; $false = "-$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"] $commitHash = $(git rev-parse --short HEAD) $buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""] From e6d3ed0ca6a53587a7c3f1ee75d07180ef401fcb Mon Sep 17 00:00:00 2001 From: Matthew Erbs Date: Sun, 21 May 2017 08:12:16 +1000 Subject: [PATCH 10/13] Changed to VS2017 AppVeyor image. --- appveyor.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index d860077..467d351 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,13 +1,7 @@ version: '{build}' skip_tags: true -image: Visual Studio 2015 +image: Visual Studio 2017 configuration: Release -install: - - ps: mkdir -Force ".\build\" | Out-Null - - ps: Invoke-WebRequest "https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/dotnet-install.ps1" -OutFile ".\build\installcli.ps1" - - ps: $env:DOTNET_INSTALL_DIR = "$pwd\.dotnetcli" - - ps: '& .\build\installcli.ps1 -InstallDir "$env:DOTNET_INSTALL_DIR" -NoPath -Version 1.0.1' - - ps: $env:Path = "$env:DOTNET_INSTALL_DIR;$env:Path" build_script: - ps: ./Build.ps1 test: off From 40eade0b28819ae4df12a42f356473d68e4d106c Mon Sep 17 00:00:00 2001 From: Matthew Erbs Date: Sun, 21 May 2017 08:43:15 +1000 Subject: [PATCH 11/13] Reverted build change to use VersionPrefix * Inconisent approaches in the Sinks. Appears that version prefix and build script is best approach. --- Build.ps1 | 2 +- src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Build.ps1 b/Build.ps1 index 18f09c5..0398317 100644 --- a/Build.ps1 +++ b/Build.ps1 @@ -12,7 +12,7 @@ if(Test-Path .\artifacts) { $branch = @{ $true = $env:APPVEYOR_REPO_BRANCH; $false = $(git symbolic-ref --short -q HEAD) }[$env:APPVEYOR_REPO_BRANCH -ne $NULL]; $revision = @{ $true = "{0:00000}" -f [convert]::ToInt32("0" + $env:APPVEYOR_BUILD_NUMBER, 10); $false = "local" }[$env:APPVEYOR_BUILD_NUMBER -ne $NULL]; -$suffix = @{ $true = ""; $false = "-$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"] +$suffix = @{ $true = ""; $false = "$($branch.Substring(0, [math]::Min(10,$branch.Length)))-$revision"}[$branch -eq "master" -and $revision -ne "local"] $commitHash = $(git rev-parse --short HEAD) $buildSuffix = @{ $true = "$($suffix)-$($commitHash)"; $false = "$($branch)-$($commitHash)" }[$suffix -ne ""] diff --git a/src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj b/src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj index 3af454a..9bd4f46 100644 --- a/src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj +++ b/src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj @@ -2,7 +2,7 @@ The Splunk Sink for Serilog - 2.1.3 + 2.2.0 Matthew Erbs, Serilog Contributors net45;netstandard1.1 true @@ -13,7 +13,6 @@ https://github.com/serilog/serilog-sinks-splunk http://www.apache.org/licenses/LICENSE-2.0 false - 2.2.0$(VersionSuffix) From bee12ffc4eccc77448768a4a9202b2ee9152c3fd Mon Sep 17 00:00:00 2001 From: avireddy02 Date: Thu, 25 May 2017 02:44:52 -0700 Subject: [PATCH 12/13] This is developed based on required and best of SplunkJsonFormatter and CompactJsonFormatter --- .../Splunk/CompactSplunkJsonFormatter.cs | 137 ++++++++++++++++++ .../CompactSplunkJsonFormatterTests.cs | 84 +++++++++++ 2 files changed, 221 insertions(+) create mode 100644 src/Serilog.Sinks.Splunk/Sinks/Splunk/CompactSplunkJsonFormatter.cs create mode 100644 test/Serilog.Sinks.Splunk.Tests/CompactSplunkJsonFormatterTests.cs diff --git a/src/Serilog.Sinks.Splunk/Sinks/Splunk/CompactSplunkJsonFormatter.cs b/src/Serilog.Sinks.Splunk/Sinks/Splunk/CompactSplunkJsonFormatter.cs new file mode 100644 index 0000000..79132fa --- /dev/null +++ b/src/Serilog.Sinks.Splunk/Sinks/Splunk/CompactSplunkJsonFormatter.cs @@ -0,0 +1,137 @@ +// Copyright 2016 Serilog Contributors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Serilog.Events; +using Serilog.Formatting; +using Serilog.Formatting.Json; +using Serilog.Parsing; +using System; +using System.Globalization; +using System.IO; +using System.Linq; + +namespace Serilog.Sinks.Splunk +{ + /// + /// Renders log events into a Compact JSON format for consumption by Splunk. + /// + public class CompactSplunkJsonFormatter : ITextFormatter + { + private static readonly JsonValueFormatter ValueFormatter = new JsonValueFormatter(typeTagName: "$type"); + private readonly string _suffix; + private readonly bool _renderTemplate; + + /// + /// Construct a . + /// + /// The source of the event + /// The source type of the event + /// The host of the event + /// The Splunk index to log to + /// If true, the template used will be rendered and written to the output as a property named MessageTemplate + public CompactSplunkJsonFormatter(bool renderTemplate = false, string source = null, string sourceType = null, string host = null, string index = null) + { + _renderTemplate = renderTemplate; + var suffixWriter = new StringWriter(); + suffixWriter.Write("}"); // Terminates "event" + + if (!string.IsNullOrWhiteSpace(source)) + { + suffixWriter.Write(",\"source\":"); + JsonValueFormatter.WriteQuotedJsonString(source, suffixWriter); + } + + if (!string.IsNullOrWhiteSpace(sourceType)) + { + suffixWriter.Write(",\"sourcetype\":"); + JsonValueFormatter.WriteQuotedJsonString(sourceType, suffixWriter); + } + + if (!string.IsNullOrWhiteSpace(host)) + { + suffixWriter.Write(",\"host\":"); + JsonValueFormatter.WriteQuotedJsonString(host, suffixWriter); + } + + if (!string.IsNullOrWhiteSpace(index)) + { + suffixWriter.Write(",\"index\":"); + JsonValueFormatter.WriteQuotedJsonString(index, suffixWriter); + } + suffixWriter.Write('}'); // Terminates the payload + _suffix = suffixWriter.ToString(); + } + + /// + public void Format(LogEvent logEvent, TextWriter output) + { + if (logEvent == null) throw new ArgumentNullException(nameof(logEvent)); + if (output == null) throw new ArgumentNullException(nameof(output)); + + output.Write("{\"time\":\""); + output.Write(logEvent.Timestamp.ToEpoch().ToString(CultureInfo.InvariantCulture)); + output.Write("\",\"event\":{\"@l\":\""); + output.Write(logEvent.Level); + output.Write('"'); + + if (_renderTemplate) + { + output.Write(",\"@mt\":"); + JsonValueFormatter.WriteQuotedJsonString(logEvent.MessageTemplate.Text, output); + + var tokensWithFormat = logEvent.MessageTemplate.Tokens + .OfType() + .Where(pt => pt.Format != null); + + // Better not to allocate an array in the 99.9% of cases where this is false + // ReSharper disable once PossibleMultipleEnumeration + if (tokensWithFormat.Any()) + { + output.Write(",\"@r\":["); + var delim = ""; + foreach (var r in tokensWithFormat) + { + output.Write(delim); + delim = ","; + var space = new StringWriter(); + r.Render(logEvent.Properties, space); + JsonValueFormatter.WriteQuotedJsonString(space.ToString(), output); + } + output.Write(']'); + } + } + if (logEvent.Exception != null) + { + output.Write(",\"@x\":"); + JsonValueFormatter.WriteQuotedJsonString(logEvent.Exception.ToString(), output); + } + + foreach (var property in logEvent.Properties) + { + var name = property.Key; + if (name.Length > 0 && name[0] == '@') + { + // Escape first '@' by doubling + name = '@' + name; + } + + output.Write(','); + JsonValueFormatter.WriteQuotedJsonString(name, output); + output.Write(':'); + ValueFormatter.Format(property.Value, output); + } + output.WriteLine(_suffix); + } + } +} \ No newline at end of file diff --git a/test/Serilog.Sinks.Splunk.Tests/CompactSplunkJsonFormatterTests.cs b/test/Serilog.Sinks.Splunk.Tests/CompactSplunkJsonFormatterTests.cs new file mode 100644 index 0000000..58a1ffb --- /dev/null +++ b/test/Serilog.Sinks.Splunk.Tests/CompactSplunkJsonFormatterTests.cs @@ -0,0 +1,84 @@ +using Newtonsoft.Json.Linq; +using Serilog.Sinks.Splunk.Tests.Support; +using System; +using System.IO; +using Xunit; + +namespace Serilog.Sinks.Splunk.Tests +{ + public class CompactSplunkJsonFormatterTests + { + private void AssertValidJson(Action act, + string source = "", + string sourceType = "", + string host = "", + string index = "") + { + StringWriter outputRendered = new StringWriter(), output = new StringWriter(); + var log = new LoggerConfiguration() + .WriteTo.Sink(new TextWriterSink(output, new CompactSplunkJsonFormatter(false, source, sourceType, host, index))) + .WriteTo.Sink(new TextWriterSink(outputRendered, new CompactSplunkJsonFormatter(true, source, sourceType, host, index))) + .CreateLogger(); + + act(log); + + // Unfortunately this will not detect all JSON formatting issues; better than nothing however. + JObject.Parse(output.ToString()); + JObject.Parse(outputRendered.ToString()); + } + + [Fact] + public void AnEmptyEventIsValidJson() + { + AssertValidJson(log => log.Information("No properties")); + } + + [Fact] + public void AMinimalEventIsValidJson() + { + AssertValidJson(log => log.Information("One {Property}", 42)); + } + + [Fact] + public void MultiplePropertiesAreDelimited() + { + AssertValidJson(log => log.Information("Property {First} and {Second}", "One", "Two")); + } + + [Fact] + public void ExceptionsAreFormattedToValidJson() + { + AssertValidJson(log => log.Information(new DivideByZeroException(), "With exception")); + } + + [Fact] + public void ExceptionAndPropertiesAreValidJson() + { + AssertValidJson(log => log.Information(new DivideByZeroException(), "With exception and {Property}", 42)); + } + + [Fact] + public void AMinimalEventWithSourceIsValidJson() + { + AssertValidJson(log => log.Information("One {Property}", 42), source: "A Test Source"); + } + + [Fact] + public void AMinimalEventWithSourceTypeIsValidJson() + { + AssertValidJson(log => log.Information("One {Property}", 42), sourceType: "A Test SourceType"); + } + + [Fact] + public void AMinimalEventWithHostIsValidJson() + { + AssertValidJson(log => log.Information("One {Property}", 42), host: "A Test Host"); + } + + [Fact] + public void AMinimalEventWithIndexIsValidJson() + { + AssertValidJson(log => log.Information("One {Property}", 42), host: "testindex"); + } + } +} \ No newline at end of file From 89454c2e65449b6190a3431d41494f7e71b4a188 Mon Sep 17 00:00:00 2001 From: avireddy02 Date: Thu, 25 May 2017 20:50:14 -0700 Subject: [PATCH 13/13] Sample for CompactSplunkJsonFormatter --- sample/Sample/Program.cs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/sample/Sample/Program.cs b/sample/Sample/Program.cs index 5cc145c..18050a9 100644 --- a/sample/Sample/Program.cs +++ b/sample/Sample/Program.cs @@ -1,5 +1,6 @@ using System.Linq; using Serilog; +using Serilog.Sinks.Splunk; namespace Sample { @@ -27,13 +28,35 @@ public static void Main(string[] args) OverridingSourceType(eventsToCreate); OverridingHost(eventsToCreate); WithNoTemplate(eventsToCreate); - + WithCompactSplunkFormatter(eventsToCreate); if (runSSL) UsingSSL(eventsToCreate); Log.Debug("Done"); } + private static void WithCompactSplunkFormatter(int eventsToCreate) + { + // Vanilla Test with full uri specified + Log.Logger = new LoggerConfiguration() + .MinimumLevel.Debug() + .WriteTo.LiterateConsole() + .WriteTo.EventCollector( + "http://localhost:8088/services/collector", + Program.EventCollectorToken,new CompactSplunkJsonFormatter()) + .Enrich.WithProperty("Serilog.Sinks.Splunk.Sample", "ViaEventCollector") + .Enrich.WithProperty("Serilog.Sinks.Splunk.Sample.TestType", "Vanilla with CompactSplunkJsonFormatter specified") + .CreateLogger(); + + + foreach (var i in Enumerable.Range(0, eventsToCreate)) + { + Log.Information("{Counter}{Message}", i, "Running vanilla loop with CompactSplunkJsonFormatter"); + } + + Log.CloseAndFlush(); + } + public static void OverridingSource(int eventsToCreate) { // Override Source