Add Serilog.Sinks.ZipFile to write logs into a zip file

This commit is contained in:
MBucari 2023-04-15 12:45:20 -06:00
parent af24c6e07b
commit e08a68219d
2 changed files with 11 additions and 3 deletions

View File

@ -5,7 +5,8 @@
<Version>10.1.0.1</Version> <Version>10.1.0.1</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Octokit" Version="5.0.2" /> <PackageReference Include="Octokit" Version="5.0.4" />
<PackageReference Include="Serilog.Sinks.ZipFile" Version="1.0.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\ApplicationServices\ApplicationServices.csproj" /> <ProjectReference Include="..\ApplicationServices\ApplicationServices.csproj" />

View File

@ -118,8 +118,15 @@ namespace AppScaffolding
private static void ensureSerilogConfig(Configuration config) 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<string>() is "File") is JToken fileSink)
{
fileSink["Name"] = "ZipFile";
config.SetNonString(serilog.DeepClone(), "Serilog");
}
return; return;
}
var serilogObj = new JObject 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", "Console" } }, // this has caused more problems than it's solved
new JObject new JObject
{ {
{ "Name", "File" }, { "Name", "ZipFile" },
{ "Args", { "Args",
new JObject new JObject
{ {