Log file data mining

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #16
    You don't. You use that class as a variable.

    Code:
    ArrayList list = new ArrayList();
    LogEntry le = new LogEntry(DateTime.Parse("12/1/2008","Something");
    list.Add(le);
    Except that you need to do something like that in a loop, reading your lines in, and then creating a new LogEntry, then adding that LogEntry into the ArrayList.

    You can use DateTime.Parse (which should work with a string like this: 03/01/2009 05:42:00 see this link for more details) or you can create a new DateTime(year, month, day, hour, minute, second.

    Comment

    • David R
      New Member
      • Dec 2008
      • 14

      #17
      An arraylist would be best if I need to do some searching and some calcualtions?

      Comment

      • Curtis Rutland
        Recognized Expert Specialist
        • Apr 2008
        • 3264

        #18
        Hard to say. An array list is a useful way to store a non-fixed-length array of objects in memory. If you were using Framework 2.0 or later I'd tell you to use a System.Collecti ons.Generic.Lis t or even a Dictionary, but that's a moot point. A dictionary would make searching easier.

        If you know the length of the array, you could just use LogEvent[numOfEvents] for less memory overhead.

        Without knowing what you need to do to these objects, yes, I'd say use an arraylist.

        But at a certain point, you're just going to have to try it out...I can't necessarily tell you what's best for your project until you have tried it and determined what the difficulties and problems are. See what you can do with this, and if you have any other problems, I'll be glad to help.

        Make sure you make a new thread for new problems, if they don't directly relate to this thread topic.

        Comment

        • David R
          New Member
          • Dec 2008
          • 14

          #19
          If i upgrade to Framework 3.5 and use the List class...
          How would i add a "Date", "Time" and "Event" to the list?
          How would I access the data in a list to count occurrances and perform calculations?

          Comment

          • Curtis Rutland
            Recognized Expert Specialist
            • Apr 2008
            • 3264

            #20
            Well, for one thing, I'd suggest holding both the date and time in one field, a DateTime field.

            As for using a List, you would do things the same way. Here's a few examples:
            Code:
            //using statement
            using System.Collections.Generic;
            
            //creating the list
            List<LogEntry> list = new List<LogEntry>();
            
            //adding an element:
            string date = "10/1/2008";
            string time = "13:15:05";
            string event = "something";
                //you would have gotten these values from your log file
            LogEvent le = new LogEvent(DateTime.Parse(date + " " + time,event);
            list.Add(le);
            
            //retrieving an entry and accessing it's data:
            LogEvent le2 = list[0]; //use whatever number it would be in the array, probably from a loop variable
            string event2 = le2.Event;
            DateTime dt = event2.DateAndTime;
            Hope that clears things up. The only difference is if you use an arraylist, you will have to cast the value like this:
            Code:
            //assuming list is an arraylist:
            LogEvent le2 = (LogEvent)list[0];

            Comment

            Working...