• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
ControlUp Community

ControlUp Community

Connect, Learn, and Grow

  • Blog
  • Podcast
  • Meetups
  • Archives
  • Categories
    • ControlUp One Platform
    • ControlUp for Apps
    • ControlUp for Compliance
    • ControlUp for Desktops
    • ControlUp Scripts & Triggers
    • ControlUp Synthetic Monitoring
    • ControlUp for VDI
  • Topics
  • Events
    • Logos & Wallpaper
    • ControlUp.com
  • Join

Creating a ControlUp Trigger to Check if Log File is Changed

Posted on December 27, 2022

A user asked about creating a trigger file that notifies an email if a log file is not changed for two days. Solutions proposed include making a custom event log entry and using the System.IO.FileSystemWatcher class. The user found a potential solution and will update the discussion with their results.


Read the entire ‘Creating a Trigger File to Check if Log File is Changed’ thread below:

I’m trying to create a trigger for a file, specifically if a log file doesn’t change in two days, we will get an email. I can see the folder alert, but nothing for files. does this exist? The application in question does not write to the Windows log or stop the service if it stops working, it only stops writing to the log file. Dumb, I know, but, you know…


The folder advanced trigger is for folder level columns in the console. https://support.controlup.com/docs/folders-view-actions


For triggering on a file you would need to think outside the box. Something to check the file via scripts and then use a scheduled trigger (limited to as low as 5 minutes) to check the log and write an event to the event log if something is found wrong.You can then create a second trigger to alert on this windows event you created if needed.That is a very interesting take. I’ll be researching this. Thanks!


Creating a custom event log entry is very easy.

“`New-EventLog –LogName Application –Source "APPLICATION ACTING A FOOL"

Write-EventLog –LogName Application –Source "APPLICATION ACTING A FOOL" –EntryType Error –EventID 999 –Message "APPLICATION ACTING A FOOL and its log file unchanged for three days. Restart the service. If this doesn’t work, perform the steps in KB 150: https://LINK_TO_HELPDESK_SOLUTIONS"“`Getting the modified date of the log file & triggering the creation of said event log entry has proven to be more difficult.I’m a VB.net guy myself so I can’t help much with the PowerShell stuff. I have used a file system watcher in VB before. Its just a .net component so you should be able to consume it with powershell. Maybe it will help? https://devblogs.microsoft.com/powershell-community/a-reusable-file-system-event-watcher-for-powershell/


You could use a Scheduled Trigger that runs every five minutes, as Landon suggested. Checking the file’s LastWriteTimeproperty would be a simple approach.

Something like this

$filePath = C:\myLog.txt

$lastWriteTime = (Get-Item $filePath).LastWriteTime

$currentDateTime = Get-Date

$timeDif = $currentDateTime – $lastWriteTime

if ($timeDif -ge [TimeSpan] "48:00:00") {

Send-MailMessage ….

}

Other approaches would be

  1. You could easily parse the timestamps from the log file if it saves timestamps
  2. Use the System.IO.FileSystemWatcher class in your script. You can use events such as "Changed", "Created", "Deleted", etc.

Thanks for the response.


I think I have this figured out.

I will update this with my findings and commands/configs.

Continue reading and comment on the thread ‘Creating a ControlUp Trigger to Check if Log File is Changed’.  Not a member? Join Here!


Categories: All Archives, ControlUp Scripts & Triggers
Topics: Automation & Alerting, Logs, Microsoft, Microsoft Windows, PowerShell, Scripts, Triggers

Ask Us Anything, Connect, Learn, and Grow with the ControlUp Community!

Login to the ControlUp Community to ask us anything, stay up-to-date on what’s new and coming soon and meet other like-minded techies like you.

Not already a member? Join Today!

Primary Sidebar

ControlUp Academy

Enroll in ControlUp Academy for expert-led technical training, equipping you with skills to effectively deploy, manage, and grow your ControlUp investment.

Learn here >

Rotating Images

Hidden Gem from our Community on Slack!

ControlUp Betas - What's Coming Next?
NEW ControlUp Features - Stay Up-to-Date!
ControlUp Scripts - Scripting, Zero to Hero
Latest KB Articles - Be the First to Learn
Did you Know - with Sivan Kroitoru
Practical Perspectives Technical Use Case Training

Video Tutorials Library

Visit our technical how-to videos, offering step-by-step tutorials on advanced features, troubleshooting, and best practices.

Watch here >

ControlUp Blog

Check out the ControlUp blog for expert advice and in-depth analysis.

Read here >

ControlUp Script Library

Visit the ControlUp technical script library, which offers a multitude of pre-built scripts and custom actions for your monitoring and troubleshooting requirements.

See here >

ControlUp Support

Visit the ControlUp support home and to delve deeper into ControlUp solutions.

Browse here >

Download ControlUp RealTime DX

Start with ControlUp for real-time end-user environment insights, swift troubleshooting, and unprecedented performance optimization. Download now.

Download here >

Footer

      

ControlUp Community
Of Techie, By Techie, For Techie!

Terms of Use | Privacy Policy | Security
Dive Deeper, Learn more at ControlUp.com

  • facebook
  • twitter
  • youtube
  • linkedin

© 2023–2025 ControlUp Technologies LTD, All Rights Reserved.

We use cookies to ensure that we give you the best experience on our website. by continuing to use this site you agree to our Cookie policy..