public static CallStackItem[] ParseCallStask(string l) { char[] splitors = { '[', ']', ' ' }; List <CallStackItem> items = new List <CallStackItem>(); try { var toks = l.Split(splitors); foreach (var t in toks.Where(o => o.Length > 0)) { try { CallStackItem c = new CallStackItem(); var toks2 = t.Split('.'); c.Class = toks2[0]; c.Method = toks2[1]; items.Add(c); } catch (Exception ex) { } } return(items.ToArray()); } catch (Exception ex) { return(null); } }
public void Add(List <string> logs) { foreach (var log in logs) { var toks = log.Split('\t'); LogEvent e = new LogEvent(); e.AppDomain = toks[1]; e.Time = toks[2]; e.ThreadID = int.Parse(toks[0]); e.Event = toks[3]; e.CallStack = CallStackItem.ParseCallStask(toks[4]); if (e.CallStack != null) { e.Source = $"{e.CallStack[0].Class}.{e.CallStack[0].Method}"; } else { e.Source = string.Empty; } lock (Events) { Events.Insert(0, e); Updated?.Invoke(); } } }
public List <LogEvent> LoadFile(string filename) { Events = new List <LogEvent>(); try { var lines = File.ReadAllLines(filename); foreach (var l in lines) { try { var toks = l.Split('\t'); LogEvent e = new LogEvent(); e.Time = toks[1]; e.AppDomain = toks[2]; e.ThreadID = int.Parse(toks[0]); e.Event = toks[3]; e.CallStack = CallStackItem.ParseCallStask(toks[4]); e.Source = $"{e.CallStack[0].Class}.{e.CallStack[0].Method}"; Events.Insert(0, e); } catch (Exception ex) { } } Updated(); return(Events); } catch (Exception ex) { return(null); } }
public bool StartListening(string name) { try { new Thread(() => { PipeSecurity pipeSa = new PipeSecurity(); pipeSa.AddAccessRule(new PipeAccessRule("Everyone", PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow)); var server = new NamedPipeServerStream($"FinnZan_{name}", PipeDirection.InOut, 4, PipeTransmissionMode.Byte, PipeOptions.None, 1024, 1024, pipeSa, HandleInheritability.Inheritable); StreamReader reader = new StreamReader(server); while (true) { try { server.WaitForConnection(); Trace.Write("connected."); server.WaitForPipeDrain(); string line = reader.ReadToEnd(); if (line != null) { var toks = line.Split('\t'); LogEvent e = new LogEvent(); e.AppDomain = toks[1]; e.Time = toks[2]; e.ThreadID = int.Parse(toks[0]); e.Event = toks[3]; e.CallStack = CallStackItem.ParseCallStask(toks[4]); if (e.CallStack != null) { e.Source = $"{e.CallStack[0].Class}.{e.CallStack[0].Method}"; } else { e.Source = string.Empty; } _logs.Insert(0, e); Updated(); } } catch (IOException ex) { Trace.Write("Disconnected."); server.Disconnect(); } catch (Exception ex) { Trace.Write(ex); Thread.Sleep(2000); } } }).Start(); return(true); } catch (Exception ex) { return(false); } }