간단한 응용 프로그램에서 System.Diagnostic.Process.Application "Y"를 사용하여 외부 프로그램 "Y"를 시작하는 "X"라는 이름을 지정할 수 있습니다. 실행하면 응용 프로그램 로그가 텍스트 파일에 기록됩니다.C#에서 외부 프로그램에 의해 작성된 로그 파일에서 richtextbox에 사용자 정의 로그를 작성하는 방법
이제 App Y 로그를 읽으려고합니다. 로그에 사용자가 묻어 내 단어로 바꾸고 서식있는 텍스트 상자에 추가하기 어려운 단어가 포함되어있는 경우 읽으려고합니다. 다음 그들이 로그 파일
private void timerLog_Tick(object sender, EventArgs e)
{
//logpath is the path to that log file
if (File.Exists(logpath))
{
Stream stream = File.Open(logpath, FileMode.Open,FileAccess.Read, FileShare.ReadWrite);
StreamReader streamReader = new StreamReader(stream);
string str = streamReader.ReadToEnd();
//rtblog is my RichTextBox
rtbLog.Text = str;
rtbLog.SelectionStart = rtbLog.Text.Length;
rtbLog.ScrollToCaret();
streamReader.Close();
stream.Close();
}
}
지금
Mon Sep 12 19:22:56 2016 Application engine version 2.0.2016 was initiated Mon Sep 12 19:22:56 2016 Windows version 6.2 (Windows 8 or greater) Mon Sep 12 19:22:56 2016 System: 64 bits system Mon Sep 12 19:22:56 2016 checking application drivers Mon Sep 12 19:22:56 2016 Drivers not found Mon Sep 12 19:22:56 2016 Attempting to perform a task Mon Sep 12 19:22:56 2016 The task failed Mon Sep 12 19:22:56 2016 Process failed,The program is exiting
을 다음과 내가 위의 각 라인을 대체하려는 자체가 읽고 로그 파일을 기록으로 단어를 추가로 내 현재 코드 읽기 내 자신의 사용자 지정 단어
와 나는이
if (str.LastIndexOf("Application engine version 2.0.2016 was initiated")>0)
{
rtbLog.SelectedText= rtbLog.SelectedText+"Application engine Started";
}
else if (str.LastIndexOf("Drivers not found")>0)
{
rtbLog.SelectedText= rtbLog.SelectedText+"Drivers were not found navigate to settings Menu to install them";
}.....
0과 같이 밖으로 시도
이 코드는 계속되지만이 코드는 첫 번째 줄 하나를 인쇄하는 루프에 들어갑니다.
어떤 조작을 수행해주십시오. 사전에
감사
그 어떤 것도 자신의 코드를 사용하여 RichTextBox에서 온 없다는 것을 매우 슬픈 rtbLog.Text = str을; 코드에서 주석 처리되었습니다. –
앱에서 사용중인 코드로 코드를 업데이트하여 살펴볼 수 있습니까? –
업데이트 된 코드는 다음과 같습니다. http://pastebin.com/93XxnF77 –