Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EventLog access is not supported on this platform #4

Open
mwithheld opened this issue Mar 10, 2023 · 2 comments
Open

EventLog access is not supported on this platform #4

mwithheld opened this issue Mar 10, 2023 · 2 comments

Comments

@mwithheld
Copy link

mwithheld commented Mar 10, 2023

When I run the sample code as admin:

#test-posheventlog.ps1
Import-Module PoShLog
Import-Module PoShLog.Sinks.EventLog
New-Logger |
    Add-SinkEventLog -Source 'PoshLogs' |
    Start-Logger
Write-InformationLog 'My message in windows event log'
Close-Logger

I get this error:

PS C:\Scripts\> .\test-posheventlog.ps1
Exception calling "EventLog" with "9" argument(s): "EventLog access is not supported on this platform."
At C:\Program Files\WindowsPowerShell\Modules\PoShLog.Sinks.EventLog\1.0.0\functions\sinks\Add-SinkEventLog.ps1:56 char:3
+         $LoggerConfig = [Serilog.LoggerConfigurationEventLogExtension ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : PlatformNotSupportedException

I have registered the event source as admin, and tested this works:

New-EventLog -LogName Application -Source PoshLogs
Write-EventLog -LogName "Application" -Source "PoshLogs"

I tried a fresh re-install of .NET 6.0.14 SDK and full machine restart.
Install was fresh today:

Install-Module -Name PoShLog
Install-Module PoShLog.Sinks.EventLog

Windows Server 2019
Powershell 7.3.3

Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -Recurse | Get-ItemProperty -Name version -EA 0 | Where { $_.PSChildName -Match '^(?!S)\p{L}'} | Select PSChildName, version

PSChildName Version  
----------- -------  
Client      4.7.03190
Full        4.7.03190
Client      4.0.0.0  

Any suggestions would be appreciated.

@mwithheld
Copy link
Author

Figured it out- it fails under PowerShell ISE but works when run in pwsh version 7

@brentbiggs
Copy link

The issue is actually a bug in serilog and .NET Foundation 4.8 affecting PS 5.1 and ISE: serilog/serilog-sinks-eventlog#49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants