Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Write-Log {
- param(
- [int]$ErrorLevel=1, # 1 - info, 2 - warning, 3 - error
- [Parameter(position=1,ValueFromPipeline=$true)][string]$Msg,
- [Parameter(position=2)][string]$Component, # source of the entry
- [Parameter(position=3)][string]$LogFile = "c:\temp\LPUlog.log",
- [switch]$break,
- [switch]$tee
- )
- if( !$Component ){ $Component = $PSCommandPath -replace '^.*\\|\.[^\.]*$' } # script name
- if( !$LogFile ){ $LogFile = $PSCommandPath -replace '\.ps1$','.log' } # <ScriptRoot>\<ScriptName>.log
- if($break){$Msg='#############################################################'}
- if($tee){Write-Output $msg}
- $TZBias = (Get-WmiObject Win32_TimeZone).bias
- $Time = "$(Get-Date -Format 'HH:mm:ss.fff')$TZBias"
- $Date = Get-Date -Format 'MM-dd-yyyy'
- $Context = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
- $LogEntry = "<![LOG[$Msg]LOG]!><time=`"$Time`" date=`"$Date`" component=`"$Component`" context=`"$Context`" type=`"$ErrorLevel`" thread=`"$pid`" file=`"`">"
- Add-Content -Path $LogFile -Value $LogEntry
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement