Serilog for powershell
PoShLog is powershell multiplatform logging module. PoShLog allows you to log structured event data into console, file and much more places easily. It's built upon great C# logging library Serilog.
If you are familiar with PowerShell, skip to Installation section. For more detailed installation instructions check out Getting started wiki.
To install PoShLog, run following snippet from powershell:
Install-Module -Name PoShLog
Minimum setup to log into console and file:
Import-Module PoShLog
# Create and start new logger
Start-Logger -FilePath 'C:\Data\my_awesome.log' -Console
Write-InfoLog 'Hurrray, my first log message!'
# Don't forget to close the logger
Close-Logger
Image 1: Windows Terminal
Image 2: C:\Data\my_awesome.log
in VS Code
Setup using pipeline fluent API:
Import-Module PoShLog
# Create new logger
New-Logger |
Set-MinimumLevel -Value Verbose |
Add-SinkFile -Path 'C:\Data\my_awesome.log' |
Add-SinkConsole |
Start-Logger
# Test all log levels
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'
# Example of formatted output
$position = @{
Latitude = 25
Longitude = 134
}
$elapsedMs = 34
Write-InfoLog 'Processed {@Position} in {Elapsed:000} ms.' -PropertyValues $position, $elapsedMs
Close-Logger
PoShLog is extensible just like Serilog. All available extensions can be found here.
These examples are just to get you started fast. For more detailed documentation please check wiki.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
- ⭐ Star the PoShLog repository
- 👍 Give me some feedback on discord
This project is licensed under the MIT License - see the LICENSE file for details.
- Serilog - serilog.net
- Icon made by Smashicons from www.flaticon.com.