test/09.log_levels.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 9" Import-Module ..\uLog.psd1 -Force Remove-Variable -Name uLOG -ErrorAction SilentlyContinue Remove-Variable -Name Log -ErrorAction SilentlyContinue Write-Host "Exemple 9.1" $log = New-uLog -Handler (New-uLogConsole), (New-uLogFile -Name temp -Path 'c:\temp\9.log_levels.ps1.log'), (New-uLogEventLog -Name 'evt') $log.Handlers.Console.Level = [loglevel]::INFO $log.Handlers.temp.Level = [loglevel]::INFO $log.Handlers.evt.Level = [loglevel]::INFO 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' Log-Warning -Message 'Watch out' Log-Warn -Message 'Watch out' Log-Error -Message 'Problem' Log-Critical -Message 'Failure' Log-Fatal -Message 'Fatal error' Write-Host "Exemple 9.2" $log.Handlers.Console.Level = [loglevel]::ERROR $log.Handlers.temp.Level = [loglevel]::ERROR $log.Handlers.evt.Level = [loglevel]::ERROR 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' Log-Warning -Message 'Watch out' Log-Warn -Message 'Watch out' Log-Error -Message 'Problem' Log-Critical -Message 'Failure' Log-Fatal -Message 'Fatal error' Write-Host "Exemple 9.3" $log.Handlers.Console.Level = [loglevel]::TRACE $log.Handlers.temp.Level = [loglevel]::TRACE $log.Handlers.evt.Level = [loglevel]::TRACE 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' Log-Warning -Message 'Watch out' Log-Warn -Message 'Watch out' Log-Error -Message 'Problem' Log-Critical -Message 'Failure' Log-Fatal -Message 'Fatal error' Write-Host "Exemple 9.4" $log.Handlers.Console.Level = [loglevel]::TRACE $pref = $VerbosePreference $VerbosePreference = 'Continue' 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' Log-Warning -Message 'Watch out' Log-Warn -Message 'Watch out' Log-Error -Message 'Problem' Log-Critical -Message 'Failure' Log-Fatal -Message 'Fatal error' $VerbosePreference = $pref |