Example #1
0
 public void RaiseSessionLog(SessionLogEntry Entry)
 {
     if (SessionLog != null)
     {
         SessionLog(Entry);
     }
 }
Example #2
0
        public static void WriteLog(String LogDir, SessionLogEntry Entry)
        {
            var LocalTime = Entry.Time.ToLocalTime();
            var Dir       = FileNameHandling.GetPath(LogDir, LocalTime.Date.ToString("yyyyMMdd"));

            if (Dir != "" && !Directory.Exists(Dir))
            {
                Directory.CreateDirectory(Dir);
            }
            var Path  = FileNameHandling.GetPath(Dir, String.Format("{0}-{1}.log", Entry.RemoteEndPoint.ToString().Replace(".", "_").Replace(":", "_"), Entry.Token));
            var e     = Encoding.UTF8;
            var Lines = GetLines(Entry);

            if (File.Exists(Path))
            {
                e = Txt.GetEncoding(Path, e);
            }
            using (var r = new StreamWriter(Path, true, e))
            {
                foreach (var Line in Lines)
                {
                    r.WriteLine(Line);
                }
            }
        }
Example #3
0
        public static String[] GetLines(SessionLogEntry Entry)
        {
            var    Time = Entry.Time.DateTimeUtcWithMillisecondsToString();
            String Start;

            {
                var l = new List <String>();
                l.Add(DecorateWithQoutesIfComplex(Time));
                l.Add(DecorateWithQoutesIfComplex(Entry.RemoteEndPoint.ToString()));
                l.Add(DecorateWithQoutesIfComplex(Entry.Token));
                l.Add(ExtendToMultipleOf(DecorateWithQoutesIfComplex(Entry.Type), 4));
                l.Add(DecorateWithQoutesIfComplex(Entry.Name));
                Start = String.Join(" ", l.ToArray());
            }
            String[] Lines;
            if (!(Entry.Message.StartsWith(" ") || Entry.Message.Contains('\n')))
            {
                Lines = new String[] { Start + " " + Entry.Message };
            }
            else
            {
                var l = new List <String>();
                l.Add(Start);
                l.Add("****************");
                foreach (var m in Entry.Message.UnifyNewLineToLf().Split('\n'))
                {
                    if (m.TrimStart(' ').StartsWith("*"))
                    {
                        l.Add(" " + m);
                    }
                    else
                    {
                        l.Add(m);
                    }
                }
                l.Add("****************");
                Lines = l.ToArray();
            }
            return(Lines);
        }
Example #4
0
 /// <summary>只能在Start之后,Stop之前调用,线程安全</summary>
 public void Push(SessionLogEntry e)
 {
     AsyncConsumer.Push(e);
 }