Skip to content
Snippets Groups Projects
Commit a6b63260 authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

Add Log-Warning(), use Category 100 for all log entries.

Plus, use Id numbers matching default output redirection ones.
parent 407b6ff1
No related branches found
No related tags found
No related merge requests found
...@@ -333,31 +333,38 @@ function Send-MailReport([string]$Subject, [string]$Body) { ...@@ -333,31 +333,38 @@ function Send-MailReport([string]$Subject, [string]$Body) {
function Log-Message([string]$Type, [string]$Message, [int]$Id){ function Log-Message([string]$Type, [string]$Message, [int]$Id){
$msg = "[$($Me)] " # NOTE: by convention, this script is setting the $Id parameter to match the
try { # numbers for the output types described in 'Help about_Redirection'
Write-EventLog ` $msg = "[$($Me)] "
try {
Write-EventLog `
-LogName Application ` -LogName Application `
-Source "AutoTx" ` -Source $ServiceName `
-Category 0 ` -Category 100 `
-EventId $Id ` -EventId $Id `
-EntryType $Type ` -EntryType $Type `
-Message "[$($Me)]: $($Message)" ` -Message "[$($Me)]: $($Message)" `
-ErrorAction Stop -ErrorAction Stop
$msg += "Logged message (Id=$($Id), Type=$($Type)).`n" $msg += "Logged message (Id=$($Id), Type=$($Type)).`n"
$msg += "--- Log Message ---`n$($Message)`n--- Log Message ---`n" $msg += "--- Log Message ---`n$($Message)`n--- Log Message ---`n"
} }
catch { catch {
$ex = $_.Exception.Message $ex = $_.Exception.Message
$msg += "Error logging message (Id=$($Id), Type=$($Type))!`n" $msg += "Error logging message (Id=$($Id), Type=$($Type))!`n"
$msg += "--- Log Message ---`n$($Message)`n--- Log Message ---`n" $msg += "--- Log Message ---`n$($Message)`n--- Log Message ---`n"
$msg += "--- Exception ---`n$($ex)`n--- Exception ---" $msg += "--- Exception ---`n$($ex)`n--- Exception ---"
} }
Write-Verbose $msg Write-Verbose $msg
}
function Log-Warning([string]$Message) {
Log-Message -Type Warning -Message $Message -Id 3
} }
function Log-Error([string]$Message){ function Log-Error([string]$Message){
Log-Message -Type Error -Message $Message -Id 1 Log-Message -Type Error -Message $Message -Id 2
} }
...@@ -369,7 +376,7 @@ function Log-Info([string]$Message) { ...@@ -369,7 +376,7 @@ function Log-Info([string]$Message) {
function Log-Debug([string]$Message) { function Log-Debug([string]$Message) {
Write-Verbose $Message Write-Verbose $Message
if ($UpdaterDebugLogging) { if ($UpdaterDebugLogging) {
Log-Message -Type Information -Message $Message -Id 1000 Log-Message -Type Information -Message $Message -Id 5
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment