diff --git a/serilog-sinks-splunk.sln b/serilog-sinks-splunk.sln index 360a961..dbe06cf 100644 --- a/serilog-sinks-splunk.sln +++ b/serilog-sinks-splunk.sln @@ -10,9 +10,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{B9B133 .editorconfig = .editorconfig Build.ps1 = Build.ps1 CHANGES.md = CHANGES.md + global.json = global.json README.md = README.md assets\Serilog.snk = assets\Serilog.snk - global.json = global.json Setup.ps1 = Setup.ps1 EndProjectSection EndProject @@ -42,6 +42,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{A9F9 .github\workflows\ci.yml = .github\workflows\ci.yml EndProjectSection EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Sinks.Splunk.TCP.Tests", "test\Serilog.Sinks.Splunk.TCP.Tests\Serilog.Sinks.Splunk.TCP.Tests.csproj", "{9F0EA87D-1D36-47C0-887E-29A1F7DB6979}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -72,6 +74,10 @@ Global {1B9DEFA3-D600-45FA-93A5-79006076FB5C}.Debug|Any CPU.Build.0 = Debug|Any CPU {1B9DEFA3-D600-45FA-93A5-79006076FB5C}.Release|Any CPU.ActiveCfg = Release|Any CPU {1B9DEFA3-D600-45FA-93A5-79006076FB5C}.Release|Any CPU.Build.0 = Release|Any CPU + {9F0EA87D-1D36-47C0-887E-29A1F7DB6979}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9F0EA87D-1D36-47C0-887E-29A1F7DB6979}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9F0EA87D-1D36-47C0-887E-29A1F7DB6979}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9F0EA87D-1D36-47C0-887E-29A1F7DB6979}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -83,6 +89,7 @@ Global {F74FCFD0-536B-4311-AA66-0BD16112D895} = {7A774CBB-A6E9-4854-B4DB-4CF860B0C1C5} {FE1504A6-5444-4B87-819C-E6F477662B7F} = {7A774CBB-A6E9-4854-B4DB-4CF860B0C1C5} {21EEF50A-C0FC-4406-97A1-8F5F499AE2FC} = {1C75E4A9-4CB1-497C-AD17-B438882051A1} + {9F0EA87D-1D36-47C0-887E-29A1F7DB6979} = {B9451AD8-09B9-4C09-A152-FBAE24806614} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {D7BFF439-D18D-4124-A36F-15CFB8E84BCC} diff --git a/test/Serilog.Sinks.Splunk.TCP.Tests/Properties/launchSettings.json b/test/Serilog.Sinks.Splunk.TCP.Tests/Properties/launchSettings.json new file mode 100644 index 0000000..3ab0635 --- /dev/null +++ b/test/Serilog.Sinks.Splunk.TCP.Tests/Properties/launchSettings.json @@ -0,0 +1,11 @@ +{ + "profiles": { + "test": { + "commandName": "test" + }, + "test-dnxcore50": { + "commandName": "test", + "sdkVersion": "dnx-coreclr-win-x86.1.0.0-rc1-final" + } + } +} \ No newline at end of file diff --git a/test/Serilog.Sinks.Splunk.TCP.Tests/Serilog.Sinks.Splunk.TCP.Tests.csproj b/test/Serilog.Sinks.Splunk.TCP.Tests/Serilog.Sinks.Splunk.TCP.Tests.csproj new file mode 100644 index 0000000..f8d5b98 --- /dev/null +++ b/test/Serilog.Sinks.Splunk.TCP.Tests/Serilog.Sinks.Splunk.TCP.Tests.csproj @@ -0,0 +1,33 @@ + + + + net462 + Serilog.Sinks.Splunk.Tests + true + false + latest + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + diff --git a/test/Serilog.Sinks.Splunk.TCP.Tests/TCPCollectorTests.cs b/test/Serilog.Sinks.Splunk.TCP.Tests/TCPCollectorTests.cs new file mode 100644 index 0000000..e66210a --- /dev/null +++ b/test/Serilog.Sinks.Splunk.TCP.Tests/TCPCollectorTests.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.NetworkInformation; +using System.Net.Sockets; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Serilog.Events; +using Xunit; + +namespace Serilog.Sinks.Splunk.TCP.Tests; + +public class TCPCollectorTests +{ + [Fact] + public void LoggerExtensionTest() + { + using (var TestEnvironment = new TestEnvironment()) + { + var log = new LoggerConfiguration() + .WriteTo.SplunkViaTcp( + new Serilog.Sinks.Splunk.SplunkTcpSinkConnectionInfo("127.0.0.1", 10001), + restrictedToMinimumLevel: LevelAlias.Minimum, + formatProvider: null, + renderTemplate: true) + .CreateLogger(); + + log.Information("Hello World"); + } + } + +} + +class TestEnvironment : IDisposable +{ + TcpListener TcpServer; + + readonly public int TcpServerAddress; + + public TestEnvironment(int TcpServerAddress = 10001) + { + this.TcpServerAddress = TcpServerAddress; + + TcpServer = new TcpListener(IPAddress.Loopback, TcpServerAddress); + + TcpServer.Start(); + } + + public void Dispose() + { + TcpServer.Stop(); + } +}