Created
October 4, 2016 14:36
-
-
Save MSAdministrator/2a0828e538b5885619b1c188fb8993c5 to your computer and use it in GitHub Desktop.
Write-LogEntry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#requires -Version 1 | |
Function Write-LogEntry | |
{ | |
param ( | |
[string]$type, | |
[string]$message, | |
[string]$Folder, | |
[string]$CustomMessage | |
) | |
[bool]$CustomMessage | |
$mutex = New-Object -TypeName 'Threading.Mutex' -ArgumentList $false, 'MyInterprocMutex' | |
switch ($type) | |
{ | |
'Error' | |
{ | |
$mutex.waitone() | |
"$((Get-Date).ToString('yyyyMMddThhmmss')) [ERROR]: $message" >> "$($Folder)\log.log" | |
if ($CustomMessage) | |
{ | |
"$((Get-Date).ToString('yyyyMMddThhmmss')) [CUSTOM MESSAGE]: $CustomMessage" >> "$($Folder)\log.log" | |
} | |
$mutex.ReleaseMutex() | |
} | |
'Info' | |
{ | |
$mutex.waitone() | |
"$((Get-Date).ToString('yyyyMMddThhmmss')) [INFO]: $message" >> "$($Folder)\log.log" | |
if ($CustomMessage) | |
{ | |
"$((Get-Date).ToString('yyyyMMddThhmmss')) [CUSTOM MESSAGE]: $CustomMessage" >> "$($Folder)\log.log" | |
} | |
$mutex.ReleaseMutex() | |
} | |
'Debug' | |
{ | |
$mutex.waitone() | |
"$((Get-Date).ToString('yyyyMMddThhmmss')) [DEBUG]: $message" >> "$($Folder)\log.log" | |
if ($CustomMessage) | |
{ | |
"$((Get-Date).ToString('yyyyMMddThhmmss')) [CUSTOM MESSAGE]: $CustomMessage" >> "$($Folder)\log.log" | |
} | |
$mutex.ReleaseMutex() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment