|
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace UndisposedLogViewer
{
class LogEntry
{
public string ObjectID;
public string Type;
public string Stack;
}
class LogParser : IDisposable
{
StreamReader streamReader;
internal LogParser(string path)
{
streamReader = new StreamReader(path);
}
internal IEnumerable<LogEntry> GetEntries()
{
while (!streamReader.EndOfStream)
{
var entry = CreateEntry(streamReader);
yield return entry;
//Eat up empty line
streamReader.ReadLine();
}
}
private LogEntry CreateEntry(StreamReader streamReader)
{
return new LogEntry()
{
ObjectID = streamReader.ReadLine(),
Type = streamReader.ReadLine(),
Stack = ReadUntilEndOfFileOrEmptyLine(streamReader)
};
}
private string ReadUntilEndOfFileOrEmptyLine(StreamReader streamReader)
{
StringBuilder builder = new StringBuilder();
string line = null;
while ((line = streamReader.ReadLine()) != null)
{
if (string.IsNullOrEmpty(line))
break;
builder.AppendLine(line);
}
return builder.ToString();
}
#region IDisposable Members
public void Dispose()
{
streamReader.Dispose();
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I'm a 27 yrs old developer working with Atmel R&D India Pvt. Ltd., Chennai. I'm currently working in C# and C++, but I've done some Java programming as well. I was a Microsoft MVP in Visual C# from 2007 to 2009.
You can read
My Blog here. I've also done some open source software - please visit my
website to know more.