I'm using a script to monitor a file. When a pattern is detected, it will send an email to notify someone.
I am creating a Windows Service via NSSM.
My question is : How can I improve performance of my script ? I have to monitor a large log file during the day. a rolling log file (log1.log, then log2.log, then log3.log etc) main log file is log.log. The time between log file rotations in seconds. Rotation time is about 2-3 seconds. Log file size is about 20-30MB.
Script :
while( $true ) {
Start-Transcript -path c:\temp\monitor_file.log
$fromaddress = "[email protected]"
$emailto = "[email protected]"
$SMTPSERVER = "xx.xx.xx.xx"
$File = "C:\temp\log.log"
Get-Content $File -Wait -Last 0 | Select-string 'Finished.' | ForEach {
Send-mailmessage -from $fromaddress -to $emailto -subject "Log changed" -smtpServer $SMTPSERVER -Encoding UTF8 -Priority High
}
}