From 9dbf53783a2bd76786533d5b344bc83db580a625 Mon Sep 17 00:00:00 2001 From: "Joseph L. Casale" <9957114+jcasale@users.noreply.github.com> Date: Sun, 24 Mar 2024 16:53:24 -0600 Subject: [PATCH 1/5] Updates to wix toolset v5.0.0. --- .github/workflows/main.yml | 39 +++++--------------------------------- src/Product.wxs | 6 +++++- 2 files changed, 10 insertions(+), 35 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8fd1f87..330b92e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,17 +24,11 @@ jobs: - name: Setup wix run: | - dotnet.exe tool install --global wix --version 4.0.4 --verbosity diag + dotnet.exe tool install --global wix --version 5.0.0 --verbosity diag - wix.exe extension add WixToolset.UI.wixext/4.0.4 --global + wix.exe extension add WixToolset.UI.wixext/5.0.0 --global wix.exe extension list --global - nuget.exe install WixToolset.Heat -Version 4.0.4 -NonInteractive -Verbosity detailed - Get-ChildItem -Path .\WixToolset.Heat* -Recurse | - Where-Object { $_.FullName.EndsWith('x64\heat.exe') } | - Select-Object -ExpandProperty DirectoryName | - Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - - name: Generate version property id: version run: | @@ -62,40 +56,17 @@ jobs: Update-MarkdownHelp ./docs -UpdateInputOutput -Force -ErrorAction Stop New-ExternalHelp ./docs -OutputPath ./publish -ErrorAction Stop - - name: Harvest installer - run: | - heat.exe ` - dir ` - .\publish ` - -nologo ` - -cg ProductComponents ` - -dr INSTALLDIR ` - -var var.ProductSource ` - -g1 ` - -ag ` - -ke ` - -srd ` - -sfrag ` - -sreg ` - -o Fragment.wxs - - name: Build installer run: | wix.exe ` build ` -arch x64 ` - -src Fragment.wxs src\Product.wxs ` - -d ProductSource=publish ` + -src src\Product.wxs ` + -d ProductSource="$(Resolve-Path ./publish)" ` -d ProductVersion="${{ steps.version.outputs.version }}" ` -ext WixToolset.UI.wixext ` -out ps-serilog.msi - - name: Update installer - run: | - $path = Resolve-Path 'C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x86\msiinfo.exe' -ErrorAction Stop - - & $path ps-serilog.msi -t "PowerShell Serilog Module" -o "PSSerilog v${{ steps.version.outputs.version }}" - - name: Validate installer run: wix.exe msi validate ps-serilog.msi @@ -127,7 +98,7 @@ jobs: - name: Publish release if: github.ref_type == 'tag' - run: gh.exe release create v${{ steps.version.outputs.version }} --notes 'PowerShell Serilog logging module.' ps-serilog.msi + run: gh.exe release create v${{ steps.version.outputs.version }} --title v${{ steps.version.outputs.version }} --notes 'PowerShell Serilog logging module.' ps-serilog.msi env: # Requires a personal access token with a fine-grained permission of contents:read/write. GH_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }} diff --git a/src/Product.wxs b/src/Product.wxs index e96dbef..5b49388 100644 --- a/src/Product.wxs +++ b/src/Product.wxs @@ -5,7 +5,7 @@ Version="$(var.ProductVersion)" Manufacturer="Joseph L. Casale" UpgradeCode="1be534ed-bed0-4704-baee-78052afff1a5"> - + @@ -40,5 +40,9 @@ + + + + \ No newline at end of file From 2d6790ed0024765bcbaad6285b969ef1e5bbefb7 Mon Sep 17 00:00:00 2001 From: "Joseph L. Casale" <9957114+jcasale@users.noreply.github.com> Date: Fri, 29 Mar 2024 15:06:51 -0600 Subject: [PATCH 2/5] Updates analyzers. --- .editorconfig | 6 +++--- src/StyleCop.ruleset | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.editorconfig b/.editorconfig index 9919dfd..41fb21f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -412,9 +412,6 @@ resharper_unused_auto_property_accessor_global_highlighting = none resharper_unused_type_global_highlighting = none resharper_redundant_name_qualifier_highlighting = none -# MA0051: Method is too long -dotnet_diagnostic.MA0051.severity = none - [*.csproj] indent_size = 2 @@ -422,4 +419,7 @@ indent_size = 2 indent_size = 2 [*.json] +indent_size = 2 + +[*.yml] indent_size = 2 \ No newline at end of file diff --git a/src/StyleCop.ruleset b/src/StyleCop.ruleset index 101a6e6..186eb89 100644 --- a/src/StyleCop.ruleset +++ b/src/StyleCop.ruleset @@ -3,6 +3,7 @@ + From 16b1addfa0f58fdaf8f6c2a5ad0b93e7f07a3f69 Mon Sep 17 00:00:00 2001 From: "Joseph L. Casale" <9957114+jcasale@users.noreply.github.com> Date: Sat, 6 Apr 2024 08:17:17 -0600 Subject: [PATCH 3/5] Updates tests. --- src/Tests/IntegrationTests.cs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/Tests/IntegrationTests.cs b/src/Tests/IntegrationTests.cs index 4d625e4..f55ac29 100644 --- a/src/Tests/IntegrationTests.cs +++ b/src/Tests/IntegrationTests.cs @@ -30,7 +30,7 @@ public void LoggerWithConsoleSinkShouldWork() { const string message = "Hello world!"; const string outputTemplate = "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff}] [{Level}] {Message:l}{NewLine}{Exception}"; - var result = string.Format(CultureInfo.InvariantCulture, " [Information] {0}\r\n", message); + var result = ((FormattableString)$" [Information] {message}\r\n").ToString(CultureInfo.InvariantCulture); var initialSessionState = InitialSessionState.CreateDefault(); @@ -66,21 +66,21 @@ public void LoggerWithConsoleSinkShouldWork() powerShell .AddStatement() .AddScript( - """ + ((FormattableString)$$""" $originalOut = [Console]::Out $writer = [IO.StringWriter]::new() try { - [Console]::SetOut($writer) - $logger.Information('Hello world!') + [Console]::SetOut($writer) + $logger.Information('{{message}}') } finally { - [Console]::SetOut($originalOut) + [Console]::SetOut($originalOut) } $writer.ToString() - """); + """).ToString(CultureInfo.InvariantCulture)); powerShell .AddStatement() @@ -164,7 +164,7 @@ public async Task LoggerWithEmailSinkShouldWork() powerShell .AddStatement() - .AddScript("$logger.Information('Hello world!')"); + .AddScript(((FormattableString)$"$logger.Information('{message}')").ToString(CultureInfo.InvariantCulture)); powerShell .AddStatement() @@ -175,14 +175,10 @@ public async Task LoggerWithEmailSinkShouldWork() Assert.False(powerShell.HadErrors); var stopWatch = Stopwatch.StartNew(); - while (stopWatch.ElapsedMilliseconds < 5000) + while (stopWatch.ElapsedMilliseconds < 5000 && messages.Count == 0) { await Task.Delay(100, cancellationTokenSource.Token); Debug.WriteLine($"Messages Count: {messages.Count}"); - if (messages.Count > 0) - { - break; - } } stopWatch.Stop(); @@ -260,7 +256,7 @@ public void LoggerWithFileSinkShouldWork() powerShell .AddStatement() - .AddScript("$logger.Information('Hello world!')"); + .AddScript(((FormattableString)$"$logger.Information('{message}')").ToString(CultureInfo.InvariantCulture)); powerShell .AddStatement() From 7d87d50d69906e97fda0f9aa6553c780b80550d8 Mon Sep 17 00:00:00 2001 From: "Joseph L. Casale" <9957114+jcasale@users.noreply.github.com> Date: Sat, 1 Jun 2024 09:54:33 -0600 Subject: [PATCH 4/5] Updates nuget packages. --- src/PSSerilog/AddSerilogSinkEmailCommand.cs | 12 ++++++------ src/PSSerilog/PSSerilog.csproj | 14 +++++++------- src/Tests/Tests.csproj | 10 +++++----- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/PSSerilog/AddSerilogSinkEmailCommand.cs b/src/PSSerilog/AddSerilogSinkEmailCommand.cs index 35f3d39..16bc0d5 100644 --- a/src/PSSerilog/AddSerilogSinkEmailCommand.cs +++ b/src/PSSerilog/AddSerilogSinkEmailCommand.cs @@ -8,11 +8,11 @@ namespace PSSerilog; using MailKit.Security; using Serilog; +using Serilog.Configuration; using Serilog.Core; using Serilog.Events; using Serilog.Formatting.Display; using Serilog.Sinks.Email; -using Serilog.Sinks.PeriodicBatching; [Cmdlet(VerbsCommon.Add, "SerilogSinkEmail")] [OutputType(typeof(LoggerConfiguration))] @@ -126,8 +126,8 @@ public class AddSerilogSinkEmailCommand : PSCmdlet [Parameter( ValueFromPipeline = false, ValueFromPipelineByPropertyName = true, - HelpMessage = "The time to wait between checking for event batches. The default is 2 seconds.")] - public TimeSpan? Period { get; set; } + HelpMessage = "The maximum delay between event batches. The default is 2 seconds.")] + public TimeSpan? BufferingTimeLimit { get; set; } [Parameter( ValueFromPipeline = false, @@ -168,7 +168,7 @@ protected override void ProcessRecord() options.ConnectionSecurity = this.ConnectionSecurity.Value; } - var batchingOptions = new PeriodicBatchingSinkOptions(); + var batchingOptions = new BatchingOptions(); if (this.EagerlyEmitFirstEvent is not null) { @@ -180,9 +180,9 @@ protected override void ProcessRecord() batchingOptions.BatchSizeLimit = this.BatchSizeLimit.Value; } - if (this.Period is not null) + if (this.BufferingTimeLimit is not null) { - batchingOptions.Period = this.Period.Value; + batchingOptions.BufferingTimeLimit = this.BufferingTimeLimit.Value; } if (this.QueueLimit is not null) diff --git a/src/PSSerilog/PSSerilog.csproj b/src/PSSerilog/PSSerilog.csproj index 2495662..ba62abe 100644 --- a/src/PSSerilog/PSSerilog.csproj +++ b/src/PSSerilog/PSSerilog.csproj @@ -7,20 +7,20 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + - - - - + + + + diff --git a/src/Tests/Tests.csproj b/src/Tests/Tests.csproj index 16ac3bc..76e4cf9 100644 --- a/src/Tests/Tests.csproj +++ b/src/Tests/Tests.csproj @@ -8,22 +8,22 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all From 9038a39d762ed3be75260bb37757986f87f63df2 Mon Sep 17 00:00:00 2001 From: "Joseph L. Casale" <9957114+jcasale@users.noreply.github.com> Date: Sun, 2 Jun 2024 16:44:05 -0600 Subject: [PATCH 5/5] Fix for https://github.com/serilog/serilog/issues/2073. --- src/PSSerilog/PSSerilog.csproj | 4 ++-- src/PSSerilog/ResolveEventHandler.ps1 | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 src/PSSerilog/ResolveEventHandler.ps1 diff --git a/src/PSSerilog/PSSerilog.csproj b/src/PSSerilog/PSSerilog.csproj index ba62abe..d97158e 100644 --- a/src/PSSerilog/PSSerilog.csproj +++ b/src/PSSerilog/PSSerilog.csproj @@ -39,7 +39,7 @@ Never - + @@ -60,7 +60,7 @@ - + diff --git a/src/PSSerilog/ResolveEventHandler.ps1 b/src/PSSerilog/ResolveEventHandler.ps1 new file mode 100644 index 0000000..ddfec6b --- /dev/null +++ b/src/PSSerilog/ResolveEventHandler.ps1 @@ -0,0 +1,22 @@ +$path = Join-Path $PSScriptRoot 'Serilog.dll' +$serilog = [Reflection.Assembly]::LoadFrom($path) +$handler = [ResolveEventHandler]{ + param($s, $a) + + if ($a.Name.StartsWith('Serilog,')) + { + return $serilog + } + + foreach($assembly in [AppDomain]::CurrentDomain.GetAssemblies()) + { + if ($assembly.FullName -eq $a.Name) + { + return $assembly + } + } + + return $null +} + +[AppDomain]::CurrentDomain.add_AssemblyResolve($handler) \ No newline at end of file