PoShLog/PoShLog
About
:nut_and_bolt: PoShLog is a cross-platform PowerShell logging module. It makes it easy to log structured event data to the console, files, and many other destinations. It is built on the Serilog C# logging library: https://serilog.net/
Developer ToolsMeasured star growth
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- +1
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
Original
Write structured log events from PowerShell to the console, files, Seq, OpenTelemetry, Elasticsearch, Splunk, syslog and more.
Quick start · Sinks · Documentation · v2 or v3? · Changelog
[!NOTE] PoShLog 3 is in preview. It is a compiled module for PowerShell 7.6+ on Windows, Linux and macOS. Install it with
-AllowPrerelease. On Windows PowerShell 5.1, use the maintained v2 line.
Why PoShLog
- Structured, not just text. Messages are templates:
{Count}stays a number that Seq, Splunk or any log backend can filter and chart. - One logger, many destinations. Send the same events to the console, a rolling file and a log server, each with its own minimum level and format.
- Built on Serilog 4. You get its levels, enrichers and formatters, and Serilog 4 sink packages can be configured directly as an advanced route (migration guide).
- Fast and familiar. A compiled binary module with the same cmdlet names and parameters as v2.
Quick start
Install-Module PoShLog -AllowPrerelease
Start-Logger -Console -FilePath './logs/app.log'
Write-InfoLog 'Copied {Count} files to {Target}' -PropertyValues 42, 'D:\Backup'
Close-Logger
Need more control? Build the logger as a pipeline: one minimum level, several sinks, each with its own settings.
New-Logger |
Set-MinimumLevel -Value Verbose |
Add-SinkConsole |
Add-SinkFile -Path './logs/app-.log' -RollingInterval Day |
Add-SinkSeq -ServerUrl 'http://localhost:5341' | # Install-Module PoShLog.Sinks.Seq
Start-Logger
Write-VerboseLog 'Starting backup of {Path}' -PropertyValues 'C:\Data'
Write-WarningLog 'Disk {Drive} is {Percent}% full' -PropertyValues 'D:', 91
Write-ErrorLog 'Backup failed' -ErrorRecord $Error[0]
Close-Logger
How it works
Sinks
Console, File and the PowerShell streams are built into PoShLog. Everything else is a small extension module you install next to it.
| Destination | Module | Install | Docs |
|---|---|---|---|
| Console, File, PowerShell streams | PoShLog | built in | Add-SinkConsole, Add-SinkFile, Add-SinkPowerShell |
| OpenTelemetry (OTLP): Grafana, .NET Aspire, Datadog, Elastic, any Collector | PoShLog.Sinks.OpenTelemetry | Install-Module PoShLog.Sinks.OpenTelemetry |
Add-SinkOpenTelemetry |
| Seq | PoShLog.Sinks.Seq | Install-Module PoShLog.Sinks.Seq |
Add-SinkSeq |
| Splunk HTTP Event Collector | PoShLog.Sinks.Splunk.Hec | Install-Module PoShLog.Sinks.Splunk.Hec |
Add-SinkSplunk |
| Syslog (RFC 5424 / 3164 over UDP, TCP, TLS) | PoShLog.Sinks.Syslog.Rfc5424 | Install-Module PoShLog.Sinks.Syslog.Rfc5424 |
Add-SinkSyslog |
| Elasticsearch and Elastic Cloud (data streams, ECS) | PoShLog.Sinks.Elastic | Install-Module PoShLog.Sinks.Elastic |
Add-SinkElasticsearch |
| HTTP endpoints | PoShLog.Sinks.Http | Install-Module PoShLog.Sinks.Http |
Add-SinkHttp |
| Windows Event Log | PoShLog.Sinks.EventLog | Install-Module PoShLog.Sinks.EventLog |
Add-SinkEventLog |
| Enrichers: environment, process, exception details | PoShLog.Enrichers | Install-Module PoShLog.Enrichers |
Enrichers |
PoShLog can list and install its extensions itself. Install-PoShLogExtension adds -Prerelease while PoShLog 3 is
in preview, so you do not have to:
Get-PoShLogExtension | Format-Table # name, kind, version, installed version, commands
Get-PoShLogExtension -Online # adds the latest version in the Gallery
Install-PoShLogExtension PoShLog.Sinks.Seq
Without it, install the extensions with Install-PSResource <module> -Prerelease while PoShLog 3 is in preview
(compatibility page, Get-PoShLogExtension,
Install-PoShLogExtension). Third-party modules and other Serilog
sinks are listed on the sinks page.
v2 or v3?
| PoShLog 3 (preview) | PoShLog 2 | |
|---|---|---|
| PowerShell | 7.6+ on Windows, Linux, macOS | Windows PowerShell 5.1 and PowerShell 7 |
| Module | compiled, Serilog 4 | script module, Serilog 2 |
| Install | Install-Module PoShLog -AllowPrerelease |
Install-Module PoShLog -MaximumVersion 2.99 |
| Status | new features | bug fixes and Serilog updates |
Moving a script over? Read v2 or v3? and the migration guide.
Documentation
- Getting started and usage
- Compatibility and installation: which versions work together, installing the preview
- Log event levels
- Cmdlet reference
- Sinks and enrichers
- Capturing output of existing scripts
- Migrating from PoShLog 2, Write-Host and transcripts or PSFramework
- FAQ and troubleshooting
- Recipes: scheduled scripts, GitHub Actions, Pester tests
- Extension modules and creating a sink
- Architectural decisions
Contributing
Pull requests are welcome. For bigger changes, please open an issue or a discussion first. Good first issues are a nice place to start, and the developer guide explains the layout.
Building locally
You need the .NET 10 SDK (or newer) and PowerShell 7.6+.
dotnet build PoShLog.sln
dotnet publish src/dotnet/PoShLog.Core.csproj -o src/lib
dotnet test PoShLog.sln
Invoke-Pester ./tests
Import-Module ./src/PoShLog.psd1
Start-Logger -Console
Write-InfoLog 'Hello from PoShLog!'
Close-Logger
Show your support
- ⭐ Star the repository. It is the simplest way to help the project.
- 💬 Share feedback and ideas in Discussions or on Discord.
- 🐞 Try the preview and report issues.
Authors and contributors
Created and maintained by Tomáš Bouda, with contributions from Michael Zimmerli, Martin Dennhardt, Brady Shober and Chris Hunt.
License
PoShLog is licensed under the MIT License. The logo and graphics in docs/assets are part of this project and covered by the same license.
Credits
- Serilog, the logging library PoShLog is built on.
- The earlier icon in
images/iconswas made by Smashicons from www.flaticon.com.
Explore related projects
Loading…