error.log archiving

Hi all,
What I’m looking to do is rename the error.log if it has a line in it which has Out of Date in it anywhere. I’m using xp pro. We use a 3rd party to write the error into the log file.
So what I want to happen is when a out of date line is wrote to the error.log that the
File will rename the error.log to some thing like this.

Error4_20_06_1.log
Error4_20_06_2.log
Error4_20_06_3.log

Will some one tell me how I cane do it?
cdb424ttmAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LordWabbitCommented:
Here is some code which should do the trick, however there are some things to consider...
- If your logs get really big then this is not the right solution
- If this app is busy reading your log as the third party tries to write to it the file will be in use and they wont be able to write.

        private void button1_Click(object sender, EventArgs e)
        {
            string PathToLogFile = @"C:\eatme\log.log";
            StreamReader myReader = new StreamReader(PathToLogFile);
            string strLog = myReader.ReadToEnd();
            myReader.Close();
            if (strLog.Contains("Out of Date"))
            {
                int intHighestFileNum = 1;
                foreach (string eleFile in System.IO.Directory.GetFiles("C:\\eatme\\Logging"))
                {
                    string[] arrBits = eleFile.Split((char)95);
                    int intFileNum = Convert.ToInt32(arrBits[3].Substring(0, arrBits[3].IndexOf(".")));
                    if (intFileNum > intHighestFileNum) intHighestFileNum = intFileNum;
                }
                intHighestFileNum++;
                string strDestPath = "C:\\eatme\\Logging\\Error" + DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + DateTime.Now.Year.ToString().Substring(2) + "_" + intHighestFileNum.ToString() + ".log";
                System.IO.File.Copy(PathToLogFile, strDestPath);
            }            
        }
0
cdb424ttmAuthor Commented:
where do I put this code you gave me?
0
LordWabbitCommented:
Sorry, into a C# application what programming language are you the most familiar with?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

cdb424ttmAuthor Commented:
Sorry vb6 is only thing I know I do have dot net but have not used it yet. I will need you to walk me through it.
0
LordWabbitCommented:
Not a problem will recode it for you, was wondering if you wanted the orginal log deleted after backing it up?  If not then the next time the log is checked it will pick up Out of Date again and archive the log again.
0
LordWabbitCommented:
Eeeeuuaarggh and to think I used to think vb6 was the greatest thing since sliced bread.  Dotnet has spoiled me rotten.
You will need to add the Microsoft Scription Runtime reference to your project.

Private Sub timerMain_Timer()
    Dim strPathToLogFile As String
    Dim strDestPath As String
    Dim strLine As String
    Dim intHighestFileNum As Integer
    Dim intFileNum As Integer
    Dim arrBits() As String
    Dim strFileName As String
    Dim oFileSystem As Scripting.FileSystemObject
    Dim oTextFile As Scripting.TextStream
    Dim oFolder As Scripting.Folder
    Dim oFiles As Scripting.Files
    Dim oFile As Scripting.File
    '-=-
    strPathToLogFile = "C:\eatme\log.log"
    strDestPath = "C:\eatme\Logging"
    Set oFileSystem = CreateObject("Scripting.FileSystemObject")
    If oFileSystem.FileExists(strPathToLogFile) = False Then Exit Sub
    Set oTextFile = oFileSystem.OpenTextFile(strPathToLogFile, ForReading)
    strLine = oTextFile.ReadAll
    oTextFile.Close
    If InStr(strLine, "Out of Date") > 0 Then
        '-=- Find the highest file number
        Set oFolder = oFileSystem.GetFolder(strDestPath)
        For Each oFile In oFolder.Files
            arrBits = Split(oFile.Name, "_")
            intFileNum = CInt(Mid(arrBits(3), 1, InStr(arrBits(3), ".")))
            If intFileNum > intHighestFileNum Then intHighestFileNum = intFileNum
        Next
        intHighestFileNum = intHighestFileNum + 1
        strFileName = "Error" & Format(Now, "mm_dd_yy") & "_" & intHighestFileNum & ".log"
        oFileSystem.CopyFile strPathToLogFile, strDestPath & "\" & strFileName, False
        oFileSystem.DeleteFile strPathToLogFile
        Set oFolder = Nothing
    End If
    Set oTextFile = Nothing
    Set oFileSystem = Nothing
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cdb424ttmAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

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.