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

Getting double output with the "Short version" #28

Open
futuremotiondev opened this issue Aug 10, 2022 · 1 comment
Open

Getting double output with the "Short version" #28

futuremotiondev opened this issue Aug 10, 2022 · 1 comment

Comments

@futuremotiondev
Copy link

Start-Logger -MinimumLevel Verbose -Console

Write-VerboseLog "Test verbose message"
Write-DebugLog "Test debug message"
Write-InfoLog "Test info message"
Write-WarningLog "Test warning message"
Write-ErrorLog "Test error message"
Write-FatalLog "Test fatal message"

Close-Logger

Results with this on Pwsh:

Code_I937b5kps4

How can I suppress the duplicates?

Note: The "Full version" works as expected:

New-Logger | Set-MinimumLevel -Value Verbose | Add-SinkConsole | Start-Logger

Write-VerboseLog "Test verbose message"
Write-DebugLog "Test debug message"
Write-InfoLog "Test info message"
Write-WarningLog "Test warning message"
Write-ErrorLog "Test error message"
Write-FatalLog "Test fatal message"

Close-Logger

Code_YFsRMlpSD6

Any help would be fantastic.

@gitbute
Copy link
Contributor

gitbute commented Aug 18, 2022

Hi @visusys

When you instantiate a new logger with the short version and do not pass a FilePath,
it adds both the Console-Sink as well as the PowerShell-Sink to the Logger.
This behaves as you have seen like you get two messages.

Be aware that those two sinks are not the same. The PowerShell sink sends it to the 'correct' PowerShell streams,
while the console sink only supports stdout / error stream.

So the short version behaves like this:

New-Logger | Set-MinimumLevel -Value Verbose | Add-SinkConsole | Add-SinkPowerShell | Start-Logger

Write-VerboseLog "Test verbose message"
Write-DebugLog "Test debug message"
Write-InfoLog "Test info message"
Write-WarningLog "Test warning message"
Write-ErrorLog "Test error message"
Write-FatalLog "Test fatal message"

Close-Logger

For your use case i would advise to just use the full syntax.

Best regards

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