Skip to content
forked from PoShLog/PoShLog

🔩 PoShLog is PowerShell multiplatform logging module. It allows you to log structured event data into console, file and much more places easily. It's built upon great C# logging library Serilog - https://serilog.net/

License

Notifications You must be signed in to change notification settings

gitbute/PoShLog

 
 

Repository files navigation

PoShLog

icon

psgallery PowerShell Gallery psgallery Discord

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.

Getting started

If you are familiar with PowerShell, skip to Installation section. For more detailed installation instructions check out Getting started wiki.

Installation

To install PoShLog, run following snippet from powershell:

Install-Module -Name PoShLog

Usage

Short version

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

poshlog_example_simplest_console

Image 1: Windows Terminal

poshlog_example_simplest_file

Image 2: C:\Data\my_awesome.log in VS Code

Full version

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

Extendability

PoShLog is extensible just like Serilog. All available extensions can be found here.

Documentation

These examples are just to get you started fast. For more detailed documentation please check wiki.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Show your support

Authors

License

This project is licensed under the MIT License - see the LICENSE file for details.

Credits

About

🔩 PoShLog is PowerShell multiplatform logging module. It allows you to log structured event data into console, file and much more places easily. It's built upon great C# logging library Serilog - https://serilog.net/

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PowerShell 100.0%