test/08.default_Handler.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<#
 
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