I need to write a C# program that will search a certain log file on about 100 machines for certain text and output that to a table or listbox or some other output.

I need to write a loop that will check a certain log file on about 100 machines and then in a list box print out the machine name, the last instance of the word "backup" in the log and the date following "date=" in the log.

Here is an example of the log:

<![LOG[Retrieved local Management Point from AD: BACKUP]LOG]!><time="13:16:03.645+300" date="10-11-2004" component="LocationServices" context="" type="1" thread="320" file="lsad.cpp:2514">

So what I need is:

Check the log file at \\machine1\C$\Windows\System32\Log\backup.log all the way through

Find last instance of the word "BACKUP" and "date=" in the log and put that into a list box or some other form of output. If "BACKUP" doesn't exist just print "No" in the listbox next to that machine name.

Hope this makes sense.

After that, I'd like to make changes to the program to allow it to interact with Active Directory and check the c:\windows\system32\Logs\backup.log on every machine in the OU that I choose.  Is that possible?

Thanks in advance,

Who is Participating?

Improve company productivity with a Business Account.Sign Up

pratap_rConnect With a Mentor Commented:
it works fine.. this is the output i get in the message box.. exactly what you are looking for..

i mean i dont see any compromising information in what you have posted so you should be safe :-)

This is usually a billable request. An entire project maybe with a deadline and, optionally, a project manager. You might also want to hire a software architect and another developer. You might also want to include your systems/infrastructure architect to offer expertise on how to make this possible on your network. Optionally, get a technical writer for the documents and a tester to complete the team.

Just kidding...

But if you can show what you've done so far then maybe we can focus on what exactly is the problem... so far, I think the problem is that you don't have the confidence to start this yourself...
sure its possible.. and heres the code... :-)

      string mcbase="machine";
      for(int i=1; i < 100; i++)
            TextReader tr=new StreamReader(@"\\"+mcbase+i+@"\c$\Windows\System32\Log\backup.log");
            string str=tr.ReadToEnd();
            Regex r=new Regex("BACKUP.*date=\"([^\"]*)\"",RegexOptions.RightToLeft);
            Match m=r.Match(str);

it does a regex match agains the words backup and date="" so you might want to change that a bit to make it match better... i have tested it against the input you gave so it should work i guess. and you might want to put in some error handling also..

next for AD... post on your requirements.. sounds like fun :-)

btw, my billing rate will be 140$ per hour.. heh :-) ... just kidding

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

jnewton03Author Commented:
Thanks for the help.  The Regular Expression is always returning "No."  I'm really bad with Regular Expressions, so are you sure that's the correct format for the log I showed above?

Also, for the AD part, I'd like to show a Tree where I can click on whichever OU I want (the Domain name is IOWA) and have the program check that log on every machine in that OU and output to a table with the following columns: (Machine Name, If it has the log with the word Backup in it (yes or no), and the date).

Eventually I'd like this to be a web application so I may end up re-writing it in ASP.Net.
yes its exactly the same log.. i copied the log line and created a file on my drive and checked it.. can you attach a few more lines.. probably its something else

for the AD part it shouldnt be a problem... just put the above code in a function which accepts the machine name as parameter and you are good to go.. just call the function whenever you click the treeview node...

Unless this is for some rotten test database, you have plain SQL in your log file including columns and table names. I don't know your enviroment the application is running, but it is a bad idea to post things like this on the net since hackers love that.
jnewton03Author Commented:
Sorry bout that.  That was the wrong log file anyways.  Here is my log file (last few entries):

<![LOG[Current AD site of machine is Default-First-Site-Name]LOG]!><time="18:07:56.880+300" date="09-30-2004" component="LocationServices" context="" type="1" thread="388" file="lsad.cpp:215">
<![LOG[Retrieved local Management Point from AD: BACKUP]LOG]!><time="18:07:56.880+300" date="09-30-2004" component="LocationServices" context="" type="1" thread="388" file="lsad.cpp:2514">
<![LOG[Current AD site of machine is Default-First-Site-Name]LOG]!><time="18:07:56.970+300" date="09-30-2004" component="LocationServices" context="" type="1" thread="388" file="lsad.cpp:215">

Should the regular expression you showed still work?

Also, someone please let me know if this is still dangerous to post (I'm bad with SQL)

Thanks again!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.