/// <summary>Creates</summary> /// <param name="dataLine"></param> public DELogLine(string dataLine) { LogLineParser.Parse(dataLine, out var typ, out var stamp, out var text); this.Stamp = stamp; this.Typ = typ; this.Text = text; } // ctor
/// <summary>Creates</summary> /// <param name="dataLine"></param> public DELogLine(string dataLine) { LogMsgType typ; DateTime stamp; string text; LogLineParser.Parse(dataLine, out typ, out stamp, out text); this.Stamp = stamp; this.Typ = typ; this.Text = text; } // ctor
} // func TryParseLogcat private async Task FetchLinesAsync(string fileName) { using (var src = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (var tr = new StreamReader(src, Encoding.Default, true)) { var buf = new LogLineBuffer(this); var state = 0; string line; while ((line = await tr.ReadLineAsync()) != null) { if (state == 0) { if (TryParseLogcat(line, buf)) { state = 2; } else { LogLineParser.Parse(line, out var typ, out var stamp, out var text); if (text != null) // valid log format { buf.Add(new LogLine(typ, stamp, text)); state = 1; } else { buf.Add(new LogLine(LogMsgType.Information, DateTime.MinValue, line)); state = 10; } } } else if (state == 1) // parse valid log { LogLineParser.Parse(line, out var typ, out var stamp, out var text); buf.Add(new LogLine(typ, stamp, text)); } else if (state == 2) { TryParseLogcat(line, buf); } else { buf.Add(new LogLine(LogMsgType.Information, DateTime.MinValue, line)); } } buf.Flush(); } } // proc FetchLinesAsync
public void ParseLogLine01() { LogMsgType t; DateTime dt; string text; LogLineParser.Parse("2014-08-05 10:04:46:402\t0\tMain: Konfiguration wird geladen...", out t, out dt, out text); Assert.AreEqual(LogMsgType.Information, t); Assert.AreEqual(new DateTime(2014, 08, 5, 10, 4, 46, 402), dt); Assert.AreEqual("Main: Konfiguration wird geladen...", text); LogLineParser.Parse("2014-08-05 10:04:46:402\t2\tMain: Konfiguration wird geladen...", out t, out dt, out text); Assert.AreEqual(LogMsgType.Error, t); Assert.AreEqual(new DateTime(2014, 08, 5, 10, 4, 46, 402), dt); Assert.AreEqual("Main: Konfiguration wird geladen...", text); }
/// <summary></summary> /// <returns></returns> public string ToLineData() { var sb = new StringBuilder(Text?.Length ?? +64); // reserve space for the string sb.Append(LogLineParser.ConvertDateTime(Stamp)) .Append('\t') .Append(((int)Typ).ToString()) .Append('\t'); foreach (var c in Text) { switch (c) { case '\n': sb.Append("\\n"); break; case '\r': break; case '\t': sb.Append("\\t"); break; case '\\': sb.Append(@"\\"); break; case '\0': sb.Append("\\0"); break; default: sb.Append(c); break; } } return(sb.ToString()); } // func GetLineData
public void ParseDateTime01() { Assert.AreEqual(new DateTime(1982, 5, 26, 3, 48, 3, 236), LogLineParser.ParseDateTime("1982-05-26 03:48:03:236")); Assert.AreEqual(new DateTime(1982, 5, 26, 15, 48, 14, 236), LogLineParser.ParseDateTime("1982-05-26 15:48:14:236")); }
public void ConvertDateTime01() { Assert.AreEqual("1982-05-26 03:48:03:236", LogLineParser.ConvertDateTime(new DateTime(1982, 5, 26, 3, 48, 3, 236))); Assert.AreEqual("1982-05-26 15:48:14:236", LogLineParser.ConvertDateTime(new DateTime(1982, 5, 26, 15, 48, 14, 236))); }