Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7715449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:23:19+00:00 2026-06-01T02:23:19+00:00

I am trying to parse a rather long log file and creating a better

  • 0

I am trying to parse a rather long log file and creating a better more manageable listing of issues.

I am able to read and parse out the individual log line by line, but what I need to do is display only unique entries, as some errors occur more often than others and are always recorded with identical text.

What I was going to try to do was create a Dictionary object to hold each unique entry and as I work through the log file, search the Dictionary object to see if the same values are already in there.

Here is a crude sample of the code I have (a work in progress, I hope I have all syntax right) that does not work. For some reason this script never sees any distinct entries (if statement never passes):

    string[] rowdta = new string[4];
    Dictionary<string[], int> dict = new Dictionary<string[], int>();
    int ctr = -1;
    if (linectr == 1)
        {
            ctr++;
            dict.Add(rowdta, ctr);
        }
        else
        {
            foreach (KeyValuePair<string[], int> pair in dict)
            {
                if ((pair.Key[1] != rowdta[1]) || (pair.Key[2] != rowdta[2])| (pair.Key[3] != rowdta[3]))
                {
                    ctr++;
                    dict.Add(rowdta, ctr);
                }
            }
        }

Some sample data:
First line

    rowdta[0]="ErrorType";
    rowdta[1]="Undefined offset: 0";
    rowdta[2]="/url/routesDisplay2.svc.php";
    rowdta[3]="Line Number 5";

2nd line

    rowdta[0]="ErrorType";
    rowdta[1]="Undefined offset: 0";
    rowdta[2]="/url/routesDisplay2.svc.php";
    rowdta[3]="Line Number 5";

3rd line

    rowdta[0]="ErrorType";
    rowdta[1]="Undefined variable: fvmsg";
    rowdta[2]="/url/processes.svc.php";
    rowdta[3]="Line Number 787";

So, with this, the Dictionary will have 2 items in it, first line and 3rd line.

I have also tried this with the following which nalso does not find any variations in the log file text.

    if (!dict.ContainsKey(rowdta)) {}

Can someone please help me get this syntax right? I am just a newbie at C# but this should be relatively straightforward. As always, I am thinking that this should be enough information to get the conversation started. If you want/need more detail, please let me know.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:23:20+00:00Added an answer on June 1, 2026 at 2:23 am

    Either create a wrapper for your strings which implements IEquatable.

    public class LogFileEntry :IEquatable<LogFileEntry>
    {
        private readonly string[] _rows;
    
        public LogFileEntry(string[] rows)
        {
            _rows = rows;
        }
    
        public override int GetHashCode()
        {
            return 
                _rows[0].GetHashCode() << 3 | 
                _rows[2].GetHashCode() << 2 | 
                _rows[1].GetHashCode() << 1 | 
                _rows[0].GetHashCode();
        }
    
        #region Implementation of IEquatable<LogFileEntry>
    
        public override bool Equals(Object obj)
        {
            if (obj == null) 
                return base.Equals(obj);
    
            return Equals(obj as LogFileEntry);  
        } 
    
        public bool Equals(LogFileEntry other)
        {
            if(other == null) 
                return false;
    
            return _rows.SequenceEqual(other._rows);
        }
    
        #endregion
    }
    

    Then use that in your dictionary:

    var d = new Dictionary<LogFileEntry, int>();
    
    var entry = new LogFileEntry(rows);
    if( d.ContainsKey(entry) )
    {
        d[entry] ++;
    } 
    else
    {
        d[entry] = 1;
    }
    

    Or create a custom comparer similar to that proposed by @dasblinkenlight and use as follows

    public class LogFileEntry 
    {
    }
    
    public class LogFileEntryComparer : IEqualityComparer<LogFileEntry>{ ... }
    
    var d = new Dictionary<LogFileEntry, int>(new LogFileEntryComparer());
    
    var entry = new LogFileEntry(rows);
    if( d.ContainsKey(entry) )
    {
        d[entry] ++;
    } 
    else
    {
        d[entry] = 1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to parse a rather large json file, and I am beginning
I have a rather complex Flat File that I'm trying to parse using SSIS.
Trying to parse an SQL string and pull out the parameters. Ex: select *
I'm trying to parse an INI file using C++. Any tips on what is
I'm trying to parse objects to XML in Delphi, so I read about calling
I have been trying to parse Java exceptions that appear in a log for
I have a file log that I would like to parse and am having
I am trying to parse a noisy input, ideally I would be able to
Trying to parse an HTML document and extract some elements (any links to text
Trying to parse Maplines for an airport. Each airport can have X number of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.