Private/Log/Test-LogSeverity.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
function Test-LogSeverity() {
    <#
    .SYNOPSIS
        Checks if message severity is greater on equal to config severity.

    .EXAMPLE
        Test-LogSeverity -MessageSeverity
    #>


    [CmdletBinding()]
    [OutputType([bool])]
    param(      
        [Parameter(Mandatory=$true)]  
        [int] 
        $MessageSeverity,

        [Parameter(Mandatory=$false)]
        [string]
        $ConfigSeverity
    )
    
    if (!$ConfigSeverity) {
        if (!$LogConfiguration -or !$LogConfiguration.LogLevel) {
            return $true
         }
         $ConfigSeverity = $LogConfiguration.LogLevel
    }

    switch ($ConfigSeverity.ToUpper()[0]) {
        'E' { $configSeverityInt = 3 }
        'W' { $configSeverityInt = 2 }
        'D' { $configSeverityInt = 0 }
        default { $configSeverityInt = 1 }
    }
    return ($MessageSeverity -ge $configSeverityInt)
}