Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. Function WriteLog-SRTProd {
  2. Param (
  3. [string]$logT,
  4. [Parameter(Mandatory=$true)][string]$level,
  5. [String]$LogFileDirT="\ServerALogs"
  6. )
  7. $RSLogfileT=(Get-ChildItem -Path $LogFileDirT | sort LastWriteTime | select -last 1).Name
  8.  
  9. ## make sure a level is correctly selected (mandatory)
  10. If ("Error","Info","Warn" -NotContains $Level){
  11. Throw “$($Environment) is not a valid name! Please use 'Error', 'Warn', or 'Info'”
  12. }
  13. If ($Level -eq "Info"){
  14. Add-Content -Path "$LogFileDirT$RSLogFileT" -Value "$(Get-Date -format MM-dd-yyyy::HH:mm:ss) INFO $logT"
  15. Write-EventLog -LogName Application -Source TEST_MAINT -EntryType Information -EventId 100 -Message $logT -Category 0
  16. }
  17. If ($Level -eq "Warn"){
  18. Add-Content -Path "$LogFileDirT$RSLogFileT" -Value "$(Get-Date -format MM-dd-yyyy::HH:mm:ss) WARN $logT"
  19. Write-EventLog -LogName Application -Source TEST_MAINT -EntryType Warning -EventId 200 -Message $logT -Category 0
  20. }
  21. If ($Level -eq "Error"){
  22. Add-Content -Path "$LogFileDirT$RSLogFileT" -Value "$(Get-Date -format MM-dd-yyyy::HH:mm:ss) ERROR $logT"
  23. Write-EventLog -LogName Application -Source TEST_MAINT -EntryType Error -EventId 300 -Message $logT -Category 0
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement