This topic contains 2 replies, has 2 voices, and was last updated by
November 17, 2018 at 7:50 pm #125414ParticipantTopics: 9Replies: 15Points: 29Rank: 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?
November 17, 2018 at 8:09 pm #125424ParticipantTopics: 5Replies: 33Points: 4Rank: Member
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)
November 19, 2018 at 12:03 pm #125555ParticipantTopics: 9Replies: 15Points: 29Rank: 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?
The topic ‘realtime log display in windows forms’ is closed to new replies.