realtime log display in windows forms

Welcome Forums General PowerShell Q&A realtime log display in windows forms

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
2 weeks, 6 days ago.

  • Author
    Posts
  • #125414

    Participant
    Points: 15
    Rank: Member

    Hello. I have a little app that uses windows forms. Part of that app should be functionality that would show content of a log file in realtime as it's added to the log.

    I know I can do something like

    Get-Content -Path "C:\Logs\log.txt" -Wait | Out-GridView -Wait

    but that's not ideal as it blocks the script and I'd like the display the output in win forms controls like RichTextBox. I've tried creating a timer and updating the RichTextBox content with the log file content on timer tick, but that loads the log file every time and is therefore terribly inefficient. Surely there must be better way to do this....

    I've also found this code https://www.codeproject.com/Tips/371229/Live-Log-Viewer but I can't really translate the C# code to PSH.

    Can anyone help?

  • #125424

    Participant
    Points: 1
    Rank: Member

    Hi John,

    I had a similar issue while using PowerShell to develop winforms.  I was able to get around it is by utilizing PowerShell jobs.  The guys at Sapien have a good blog post on this. (it would be ideal if you are using PowerShell Studio, But if you read the code you can get an idea)

    https://www.sapien.com/blog/2012/05/16/powershell-studio-creating-responsive-forms/

     

     

  • #125555

    Participant
    Points: 15
    Rank: Member

    Thanks for the suggestion. Jobs or timer will help with the application being (b)locked part, but I don't know then how to monitor the log and display only the changes. Since in that scenario, I (assume) can't use the get-content -wait -tail approach.

    Can you elaborate little more?

You must be logged in to reply to this topic.