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

  • Home
  • SEARCH
  • 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 7928787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:50:51+00:00 2026-06-03T19:50:51+00:00

so I’m trying to upload then parse a text file with the following format:

  • 0

so I’m trying to upload then parse a text file with the following format:

Mar 29 19:23:51,667|DEBUG|1    |1: Initializing lorem ipsum…
Mar 29 19:23:31,682|ERROR|1    |1: Lorem.Ipsum.Exception while starting Foo.Bar.Launcher
System.Blah.LoremException: Lorem ipsum dolor sit amet, consectetur adipisicing elit…
    at System.Lorem.Ipsum.Dolor.foo()
    at System.Lorem.Ipsum.Dolor.foo()
…
Mar 30 22:23:23,667|DEBUG|1    |1: Initializing lorem ipsum…
Apr 02 17:24:17,413|ERROR|4    |4: Lorem failed to ipsum… System.DolorException: Object reference not set to an instance of an object.
    at Lorem.Ipsum.Dolor.IpsumDbController..ctor()

And the Error class:

public class Error
{
    public int ID { get; set; }
    public string Date { get; set; }
    public string Description { get; set; }
    public string ErrorType { get; set; }
}

Where There are Two Errors:

Error 1

Mar 29 19:23:33 – is the Date
System.Blah.LoremException – is the ErrorType.
Lorem ipsum dolor sit amet, consectetur adipisicing elit – is the Description

Error 2

Apr 02 17:24:17 – is the Date
System.DolorException – is the ErrorType.
Object reference not set to an instance of an object. – is the Description

Is there an easy way I can parse the string (through regex? or not?)? I was thinking of splitting the string if it contains ERROR, then getting the next line to assign to ErrorType.

I’m not quite sure how I would go with this, so any help will be appreciated!

UPDATE : The pattern is really inconsistent, so I’m not really confident with the String.Split solution.

The general rule is:

All |ERROR| will have a Date (our string Date), System.blah.LoremException (our ErrorType) followed by an Exception message (our Description)

The ErrorType & Description could possibly be inline with the ERROR string or on the next line.

  • 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-03T19:50:53+00:00Added an answer on June 3, 2026 at 7:50 pm

    I would use a combination of a StreamReader and Regular Expressions to handle parsing.

        private static List<Error> ParseErrors(string filepath)
        {
            Regex parser = new Regex(@"^(?<date>\w{3}\s\d{1,2}\s\d{1,2}(?::\d{1,2}){2}),[^\|]+\|ERROR\|[^:]+\s*(?<description>.+)$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            string line = string.Empty;
            Match curMatch = null;
            var errorLog = new List<Error>();
    
            using (StreamReader sReader = new StreamReader(filepath))
            {
                while (!sReader.EndOfStream && (line = sReader.ReadLine()) != null)
                {
                    curMatch = parser.Match(line);
                    if (curMatch.Success)
                    {
                        errorLog.Add(new Error()
                        {
                            ID = errorLog.Count, /* not sure how you assign ids? */
                            Date = curMatch.Groups["date"].Value.Trim(),
                            Description = curMatch.Groups["description"].Value.Trim(),
                            ErrorType = sReader.ReadLine().Trim()
                        });
                    }
                }
            }
            return errorLog;
        }
    

    The logic behind this is basically to iterate through the stream line-by-line searching for a match to the regular expression. The regular expression itself is tailored to fit only “ERROR” lines, so it won’t match on “DEBUG” etc.

    If the line matches the expression, a new “Error” class instance is put into the list, and the parsed values from the Regular Expression are used to populate the fields. To fill the “ErrorType” field, I simply read the next line following the match.

    EDIT

    Okay, the best way I can see is by matching the trailing “…” at the end of the error messages when the exception is on the same line, then attempting to match further.

    Revised code:

        private static List<Error> ParseErrors(string filepath)
        {
            Regex parser = new Regex(@"^(?<date>\w{3}\s\d{2}\s\d{1,2}(?::\d{1,2}){2}),[^\|]+\|ERROR\|[^:]+:\s*(?<description>.+?)(?:\.\.\.\s*(?<type>.+))?$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            string line = string.Empty;
            Match curMatch = null;
            var errorLog = new List<Error>();
    
            using (StreamReader sReader = new StreamReader(filepath))
            {
                while (!sReader.EndOfStream && (line = sReader.ReadLine()) != null)
                {
                    curMatch = parser.Match(line);
                    if (curMatch.Success)
                    {
                        errorLog.Add(new Error()
                        {
                            ID = errorLog.Count, /* not sure how you assign ids? */
                            Date = curMatch.Groups["date"].Value.Trim(),
                            Description = curMatch.Groups["description"].Value.Trim(),
                            ErrorType = (curMatch.Groups["type"].Success ? curMatch.Groups["type"].Value : sReader.ReadLine().Trim())
                        });
                    }
                }
            }
            return errorLog;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to render a haml file in a javascript response like so:
i want to parse a xhtml file and display in UITableView. what is the
I have a reasonable size flat file database of text documents mostly saved in
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into

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.