diff --git a/sample/SampleAppSettingsConfig/Program.cs b/sample/SampleAppSettingsConfig/Program.cs new file mode 100644 index 0000000..91ad680 --- /dev/null +++ b/sample/SampleAppSettingsConfig/Program.cs @@ -0,0 +1,51 @@ +using System; +using System.Globalization; +using Microsoft.Extensions.Configuration; +using Serilog; +using Serilog.Context; +using Serilog.Core; + +namespace SampleAppSettingsConfig +{ + public class Program + { + public static void Main() + { + //SetupLogglyConfiguration(); + using (var logger = CreateLogger(@"C:\test\Logs\")) + { + //The messages being used here are the same as the set in the SampleDurableLoggle project + logger.Information("Test message - app started"); + + logger.Warning("Test message with {@Data}", new { P1 = "sample", P2 = DateTime.Now }); + logger.Warning("Test2 message with {@Data}", new { P1 = "sample2", P2 = 10 }); + logger.Information("Second test message"); + logger.Warning("Second test message with {@Data}", new { P1 = "sample2", P2 = DateTime.Now, P3 = DateTime.UtcNow, P4 = DateTimeOffset.Now, P5 = DateTimeOffset.UtcNow }); + logger.Information("Third test message"); + logger.Warning("Third test message with {@Data}", new { P1 = "sample3", P2 = DateTime.Now }); + 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(); + } + } + + static Logger CreateLogger(string logFilePath) + { + //write selflog to stderr + Serilog.Debugging.SelfLog.Enable(Console.Error); + + var configuration = new ConfigurationBuilder() + .AddJsonFile("appsettings.json") + .Build(); + + return new LoggerConfiguration() + .ReadFrom.Configuration(configuration) + .MinimumLevel.Debug() + .CreateLogger(); + } + } +} diff --git a/sample/SampleAppSettingsConfig/SampleAppSettingsConfig.csproj b/sample/SampleAppSettingsConfig/SampleAppSettingsConfig.csproj new file mode 100644 index 0000000..d7aac50 --- /dev/null +++ b/sample/SampleAppSettingsConfig/SampleAppSettingsConfig.csproj @@ -0,0 +1,27 @@ + + + + Exe + netcoreapp3.1 + + + + + Always + + + + + + + + + + + + + + + + + diff --git a/sample/SampleAppSettingsConfig/appsettings.json b/sample/SampleAppSettingsConfig/appsettings.json new file mode 100644 index 0000000..62fe04f --- /dev/null +++ b/sample/SampleAppSettingsConfig/appsettings.json @@ -0,0 +1,31 @@ +{ + "Serilog": { + "Using": [ + "Serilog.Sinks.Console", + "Serilog.Sinks.Loggly" + ], + "WriteTo": [ + { + "Name": "Console" + }, + { + "Name": "Loggly", + "Args": { + "tags": "someSampleTag", + "customerToken": "", + "endpointHostName": "logs-01.loggly.com", + "isEnabled": "true" + } + } + ], + "Enrich": [ + "FromLogContext", + "WithExceptionDetails", + "WithThreadId" + ], + "Properties": { + "Application": "SampleAppSettingsConfig", + "Environment": "someSampleTag" + } + } +} \ No newline at end of file diff --git a/serilog-sinks-loggly.sln b/serilog-sinks-loggly.sln index 87ca0dd..c79295d 100644 --- a/serilog-sinks-loggly.sln +++ b/serilog-sinks-loggly.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26430.12 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29613.14 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{037440DE-440B-4129-9F7A-09B42D00397E}" EndProject @@ -24,6 +24,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Sinks.Loggly.Tests" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "sampleDurableLogger", "sample\sampleDurableLogger\sampleDurableLogger.csproj", "{A47ED1CE-FE7C-444E-9391-10D6B60519C2}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleAppSettingsConfig", "sample\SampleAppSettingsConfig\SampleAppSettingsConfig.csproj", "{FB985371-5BEF-4738-85F0-45779E59D56E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -42,6 +44,10 @@ Global {A47ED1CE-FE7C-444E-9391-10D6B60519C2}.Debug|Any CPU.Build.0 = Debug|Any CPU {A47ED1CE-FE7C-444E-9391-10D6B60519C2}.Release|Any CPU.ActiveCfg = Release|Any CPU {A47ED1CE-FE7C-444E-9391-10D6B60519C2}.Release|Any CPU.Build.0 = Release|Any CPU + {FB985371-5BEF-4738-85F0-45779E59D56E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FB985371-5BEF-4738-85F0-45779E59D56E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FB985371-5BEF-4738-85F0-45779E59D56E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FB985371-5BEF-4738-85F0-45779E59D56E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -50,5 +56,9 @@ Global {94E6E098-11A0-43CF-B0CF-4BA270CE9DBD} = {037440DE-440B-4129-9F7A-09B42D00397E} {120C431E-479C-48C7-9539-CFA32399769C} = {2B558B69-8F95-4F82-B223-EBF60F6F31EE} {A47ED1CE-FE7C-444E-9391-10D6B60519C2} = {FD377716-21BA-45D1-9580-02C2BECA5BAB} + {FB985371-5BEF-4738-85F0-45779E59D56E} = {FD377716-21BA-45D1-9580-02C2BECA5BAB} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {0E5AE13F-FE25-44B3-8F9B-70A4298A6128} EndGlobalSection EndGlobal