test/11.log_keep_data.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 11"

Import-Module ..\uLog.psd1 -Force -WarningAction SilentlyContinue

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

Write-Host "EXAMPLE 11.1"

$evt = New-uLogEventLog -Name 'evt' -Keep
# Keep is specified, so Log-* will not create an eventlog entry, only when
# Flush() will be used

$log = New-uLog -Handler $evt -NoHeader

Log-Trace       -Message "Trace Hello"

Log-Verbose     -Message "Verbose Hello"
Log-Debug       -Message "Debug Hello"
Log-Success     -Message 'YES !'
Log-Info        -Message 'Hello' 
Log-Information -Message 'Hello' 

$evt.Flush() # now the entry is created in the event log
$evt.Keep = $false # we set Keep to false, so every Log-* wilm create an
                   # eventlog entry

Log-Warning     -Message 'Watch out'
Log-Warn        -Message 'Watch out'
Log-Error       -Message 'Problem'
Log-Critical    -Message 'Failure'
Log-Fatal       -Message 'Fatal error'