void Start(object newSocket) { try { using (var socket = (Socket)newSocket) using (var ns = new NetworkStream(socket, FileAccess.Read, false)) using (var reader = new StreamReader(ns)) { while (_socket != null) { var entry = reader.ReadLine(); if (string.IsNullOrEmpty(entry)) { continue; } var elements = entry.Split(ElementSeperator); var dateBinaryStr = elements[0]; var date = DateTime.FromBinary(long.Parse(dateBinaryStr)); var logName = elements[1]; var level = elements[2]; var message = entry.Substring(dateBinaryStr.Length + logName.Length + level.Length + 3); var content = string.Format("{0} {1}", date.ToString("HH:mm:ss"), message); var writer = LogWriters.GetWriter(logName, date); writer.WriteLine(content); writer.Flush(); } } } catch (Exception e) { Console.WriteLine(e); Logger.Error(e); } }
static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => { Console.WriteLine("CurrentDomain UnhandledException. {0}", (eventArgs.ExceptionObject as Exception).ToString()); }; TaskScheduler.UnobservedTaskException += (sender, eventArgs) => { Console.WriteLine("TaskScheduler UnobservedTaskException. {0}", eventArgs.Exception.ToString()); }; LogWriters.Init(); var receiver = new TcpReceiver(); receiver.Initialize(); while (true) { Thread.Sleep(10000); } }