Home
Softono
PoShLog

PoShLog

Open source MIT PowerShell
235
Stars
23
Forks
13
Issues
10
Watchers
3 years
Last Commit

About PoShLog

PoShLog is a cross-platform PowerShell logging module that enables you to log structured event data to various destinations including the console and files. Built on top of the C logging library Serilog, it provides a clean and easy-to-use API for PowerShell users. Key features include structured log event data, a simple API with cmdlets like New-Logger, Add-SinkConsole, Add-SinkFile, and Start-Logger, cross-platform support, and easy extensibility through extension modules. You can log at multiple levels such as verbose, debug, info, warning, error, and fatal, and include formatted property values in your log messages. PoShLog supports both a fluent pipeline API for detailed configuration and a simplified Start-Logger syntax for quick setup. It is installable via the PowerShell Gallery using Install-Module PoShLog.

Platforms

Web Self-hosted

Languages

PowerShell

Links

icon

PoShLog

psgallery psgallery Discord Build Status Support

Serilog for powershell

PoShLog is powershell cross-platform 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.

Key Features

  • [x] Structured log event data
  • [x] Clean and easy to use API
  • [x] Cross-platform
  • [x] Easily extensible

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 PoShLog

Usage

Setup logger using pipeline fluent API and write some log messages(in this case into file and console):

Import-Module PoShLog

# Create new logger
# This is where you customize, when and how to log
New-Logger |
    Set-MinimumLevel -Value Verbose | # You can change this value later to filter log messages
    # Here you can add as many sinks as you want - see https://github.com/PoShLog/PoShLog/wiki/Sinks for all available sinks
    Add-SinkConsole |   # Tell logger to write log messages to console
    Add-SinkFile -Path 'C:\Data\my_awesome.log' | # Tell logger to write log messages into file
    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'

Close-Logger

poshlog_example_fullversion

For detailed documentation see wiki

You can(and you should) log formatted data:

Write-InfoLog 'Current date and time is {DateTime}' -PropertyValues (Get-Date)

# Some example data
$position = @{
    Latitude = 25
    Longitude = 134
}
$elapsedMs = 34

Write-InfoLog 'Processed {@Position} in {Elapsed:000} ms.' -PropertyValues $position, $elapsedMs

poshlog_example_simplest_console

Fluent API is too bulky? You don't need extra sinks? Use short setup version(logs into console and file):

# 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

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

  • :star: Star the PoShLog repository. This is the least you can do to support this project.
  • :thumbsup: Give us some feedback or suggest features using Discussions or discord
  • :mag_right: Test PoShLog and raise issues
  • Contribute :rocket: you can start with good first issues

Contributors

Building Locally

  1. Install PoShLog.Tools

     Install-Module -Name PoShLog.Tools -Force -Verbose -Scope CurrentUser
  2. Import PoShLog.Tools

     Import-Module -Name PoShLog.Tools
  3. Bootstrap the required modules

     Bootstrap '.\cd\RequiredModules.psd1'
  4. Run the build script

     Invoke-Build '.\src\PoShLog.Build.ps1' -Configuration '(Dev/Prod)' -Task Clean, BuildDependencies, CopyModuleFiles -ModuleVersion "$(MajorVersion).$(MinorVersion).$(BugfixVersion)"

Authors

Release Notes

License

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

Credits