Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function WriteLog-SRTProd {
- Param (
- [string]$logT,
- [Parameter(Mandatory=$true)][string]$level,
- [String]$LogFileDirT="\ServerALogs"
- )
- $RSLogfileT=(Get-ChildItem -Path $LogFileDirT | sort LastWriteTime | select -last 1).Name
- ## make sure a level is correctly selected (mandatory)
- If ("Error","Info","Warn" -NotContains $Level){
- Throw “$($Environment) is not a valid name! Please use 'Error', 'Warn', or 'Info'”
- }
- If ($Level -eq "Info"){
- Add-Content -Path "$LogFileDirT$RSLogFileT" -Value "$(Get-Date -format MM-dd-yyyy::HH:mm:ss) INFO $logT"
- Write-EventLog -LogName Application -Source TEST_MAINT -EntryType Information -EventId 100 -Message $logT -Category 0
- }
- If ($Level -eq "Warn"){
- Add-Content -Path "$LogFileDirT$RSLogFileT" -Value "$(Get-Date -format MM-dd-yyyy::HH:mm:ss) WARN $logT"
- Write-EventLog -LogName Application -Source TEST_MAINT -EntryType Warning -EventId 200 -Message $logT -Category 0
- }
- If ($Level -eq "Error"){
- Add-Content -Path "$LogFileDirT$RSLogFileT" -Value "$(Get-Date -format MM-dd-yyyy::HH:mm:ss) ERROR $logT"
- Write-EventLog -LogName Application -Source TEST_MAINT -EntryType Error -EventId 300 -Message $logT -Category 0
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement