From e08a68219d5333a17a4500785009124a78a8c362 Mon Sep 17 00:00:00 2001 From: MBucari Date: Sat, 15 Apr 2023 12:45:20 -0600 Subject: [PATCH] Add Serilog.Sinks.ZipFile to write logs into a zip file --- Source/AppScaffolding/AppScaffolding.csproj | 3 ++- Source/AppScaffolding/LibationScaffolding.cs | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Source/AppScaffolding/AppScaffolding.csproj b/Source/AppScaffolding/AppScaffolding.csproj index dd435e37..402deee2 100644 --- a/Source/AppScaffolding/AppScaffolding.csproj +++ b/Source/AppScaffolding/AppScaffolding.csproj @@ -5,7 +5,8 @@ 10.1.0.1 - + + diff --git a/Source/AppScaffolding/LibationScaffolding.cs b/Source/AppScaffolding/LibationScaffolding.cs index fbe45a4e..efaaf63b 100644 --- a/Source/AppScaffolding/LibationScaffolding.cs +++ b/Source/AppScaffolding/LibationScaffolding.cs @@ -118,8 +118,15 @@ namespace AppScaffolding private static void ensureSerilogConfig(Configuration config) { - if (config.GetObject("Serilog") is not null) + if (config.GetObject("Serilog") is JObject serilog) + { + if (serilog["WriteTo"] is JArray sinks && sinks.FirstOrDefault(s => s["Name"].Value() is "File") is JToken fileSink) + { + fileSink["Name"] = "ZipFile"; + config.SetNonString(serilog.DeepClone(), "Serilog"); + } return; + } var serilogObj = new JObject { @@ -129,7 +136,7 @@ namespace AppScaffolding // new JObject { {"Name", "Console" } }, // this has caused more problems than it's solved new JObject { - { "Name", "File" }, + { "Name", "ZipFile" }, { "Args", new JObject {