Skip to content

A log4net compatible PowerShell logger with custom appenders support!

License

Notifications You must be signed in to change notification settings

posh-projects/Logger

Repository files navigation

Logo Logger

Powershellgallery Badge

Install

PS> Install-Module Logger
using module Logger

$logger = New-Object Logger
$logger.appenders.add([Logger.ColoredConsoleAppender]@{ })
$logger.appenders.add([Logger.FileAppender]@{ logPath = ('{0}\Logs\miner.log' -f $PSScriptRoot) })

$logger.error('ColoredConsole Appender')
using module Logger

class CustomEntry: Logger.ILoggerEntry
{
    static [Logger.ILoggerEntry]yield([String]$text)
    {
        return [Logger.ILoggerEntry]@{
            severity = [Logger.LoggingEventType]::((Get-PSCallStack)[$true].functionName)
            message = '{1}xxx {0} xxx{1}' -f $text, [Environment]::NewLine
        }
    }
}

$logger = New-Object Logger
$logger.logEntryType = [CustomEntry]
$logger.appenders.add([Logger.ColoredConsoleAppender]@{ })

$logger.error('Custom Entry')
using module Logger

class CustomAppender: Logger.ILoggerAppender
{
    [void]log([Logger.ILoggerEntry]$entry)
    {
        Write-Host $entry.message -ForegroundColor Blue
    }
}

$logger = New-Object Logger
$logger.appenders.add([CustomAppender]@{ })

$logger.error('Custom Appender')

About

A log4net compatible PowerShell logger with custom appenders support!

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published