Skip to content

Serilog.Sinks.EventLog fails Windows validation in .Net Foundation 4.8.1 #49

@brentbiggs

Description

@brentbiggs

Basic functional test failing on PS 5.1, but works with PS 7.3. Other tested serilog.sinks (File, Console) function as expected.

Error seems to be centered around this line:

throw new PlatformNotSupportedException(RuntimeInformation.OSDescription);

Failed case with PowerShell 5.1 .NET Foundation 4.8.1:

PS C:\> $serilog = Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\PoShLog\2.1.1\lib\Serilog.dll" -PassThru
PS C:\> $serilogEventLog = Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\PoShLog.Sinks.EventLog\1.0.0\lib\Serilog.Sinks.Eventlog.dll" -PassThru
PS C:\> $config = New-Object Serilog.LoggerConfiguration
PS C:\> [Serilog.LoggerConfigurationEventLogExtensions]::EventLog($Config.WriteTo,'Application')                                                             Exception calling "EventLog" with "2" argument(s): "EventLog access is not supported on this platform." 
At line:1 char:1
+ [Serilog.LoggerConfigurationEventLogExtensions]::EventLog($Config.Wri ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : PlatformNotSupportedException
PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.3031
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.3031
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Passed case with PowerShell 7.3.4 .NET 7:

PS C:\> $serilog = Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\PoShLog\2.1.1\lib\Serilog.dll" -PassThru
PS C:\> $serilogEventLog = Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\PoShLog.Sinks.EventLog\1.0.0\lib\Serilog.Sinks.Eventlog.dll" -PassThru
PS C:\> $config = New-Object Serilog.LoggerConfiguration
PS C:\> [Serilog.LoggerConfigurationEventLogExtensions]::EventLog($Config.WriteTo,'Application')

WriteTo      : Serilog.Configuration.LoggerSinkConfiguration
AuditTo      : Serilog.Configuration.LoggerAuditSinkConfiguration
MinimumLevel : Serilog.Configuration.LoggerMinimumLevelConfiguration
Enrich       : Serilog.Configuration.LoggerEnrichmentConfiguration
Filter       : Serilog.Configuration.LoggerFilterConfiguration
Destructure  : Serilog.Configuration.LoggerDestructuringConfiguration
ReadFrom     : Serilog.Configuration.LoggerSettingsConfiguration


PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.4
PSEdition                      Core
GitCommitId                    7.3.4
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions