1 Reply Latest reply: Mar 29, 2012 3:52 PM by aLTeReGo RSS

Problem monitoring two or more files with the same name using built in Powershell Log Parser

mdriskell

So I ran into an issue trying to monitor two files on a server with the same name but in different directories.

C:\Path1\Errorlog.txt C:\Path2\Errorlog.txt

It took me a while to figure out what was causing the issue and why the monitor wasn't working accurately but I narrowed it down to the fact that powershell was outputting the count to a temp file as new-errorlog.txt-1  it stripped off the path and therefore the temp file was the same for both monitors. The script utilizes that count to see if new rows have appeared since the last poll. 

To correct this I altered this section of the log parser script.

$filename = split-path "$logfile_path" -leaf
$t = (Get-Childitem env:temp).value
$file_path = "$t\$usage-$filename-$position"

I changed it to look like this (If there is a cleaner way I'm open to suggestions....still getting a hang on this powershell scripting)

$filename = "$logfile_path"
$t = (Get-Childitem env:temp).value
$filename = $filename.Replace(':','_')
$filename = $filename.Replace('\','_')
$file_path = "$t\SW_Script_Monitor- $usage-$filename-$position"

Now my tempfiles have the full path in the name (along with some text that tells me they are from SolarWinds) the result is now

SW_ScriptMonitor-New-C__Path1_Errorlog.txt-1 and SW_ScriptMonitor-New-C__Path2_Errorlog.txt-1 

I know it probably doesn't come up a lot but in this particular case I had four logs to monitor in different directories all with the same filename.  I'm sure I won't be the only one to run into this so I felt I should share.