test/08.default_Handler.ps1

<#
 
If handlers are added to the logger at initialization time,
no console handler is created, because we suppose that we need total control
over the handlers.
 
to create a default console handler, initiliaze first the logger, then add
some handlers.
 
We can also create the logger with -NoDefaultHandler parameter to remove the default
console handler.
 
#>



Write-Host "EXAMPLE 8.1"

Import-Module ..\uLog.psd1 -Force

Remove-Variable -Name uLOG -ErrorAction SilentlyContinue
Remove-Variable -Name Log -ErrorAction SilentlyContinue


$local = New-uLogFile -Name local

$temp = New-uLogFile -Name temp -Path c:\temp\8.1.default_Handler.ps1.log

$evt = New-uLogEventLog 

$log = New-uLog -Handler $local, $temp, $evt


Log-Info -Message '8.1 Hello' -Exclude $evt, $temp, ($log.Handlers | ? Name -EQ Console)
Log-Warning -Message '8.1 Watch out' -Indent 3 -NoDisplayOnTerminal
Log-Info -Message '8.1 Hello'
Log-Success '8.1 YES !'
Log-Error '8.1 Problem'
Log-Critical '8.1 Failure'
Write-Log -Message '8.1 Youpi' -Level SUCCESS


Write-Host "EXAMPLE 8.2"

Import-Module ..\uLog.psd1 -Force

Remove-Variable -Name uLOG -ErrorAction SilentlyContinue
Remove-Variable -Name Log -ErrorAction SilentlyContinue


$log = New-uLog -NoDefaultHandler

$local = New-uLogFile -Name local
$log.AddLogHandler($local)

$temp = New-uLogFile -Name temp -Path c:\temp\8.2.default_Handler.ps1.log

$log.AddLogHandler($temp)

$evt = New-uLogEventLog 
$log.AddLogHandler($evt)


Log-Info -Message '8.2 Hello' -Exclude $evt, $temp, ($log.Handlers | ? Name -EQ Console)
Log-Warning -Message '8.2 Watch out' -Indent 3 -NoDisplayOnTerminal
Log-Info -Message '8.2 Hello'
Log-Success '8.2 YES !'
Log-Error '8.2 Problem'
Log-Critical '8.2 Failure'
Write-Log -Message '8.2 Youpi' -Level SUCCESS