Esempio n. 1
0
        protected string FormatLogEntry(LogEntry entry)
        {
            var messageBuilder = new StringBuilder();
            var messages = entry.Message.Split('\n').GetEnumerator();
            messages.MoveNext();

            if(entry.ObjectName != null)
            {
                var currentEmulation = EmulationManager.Instance.CurrentEmulation;
                var machineCount = currentEmulation.MachinesCount;
                if(machineCount > 1 && entry.MachineName != null)
                {
                    messageBuilder.AppendFormat("{2}/{0}: {1}", entry.ObjectName, messages.Current, entry.MachineName);
                }
                else
                {
                    messageBuilder.AppendFormat("{0}: {1}", entry.ObjectName, messages.Current);
                }
            }
            else
            {
                messageBuilder.Append(messages.Current);
            }
            while(messages.MoveNext())
            {
                messageBuilder.Append(Environment.NewLine);
                messageBuilder.Append("    ");
                messageBuilder.Append(messages.Current);
            }
            return messageBuilder.ToString();
        }
Esempio n. 2
0
 public bool EqualsWithoutIdAndTime(LogEntry entry)
 {
     return entry != null &&
         numericLogLevel == entry.numericLogLevel &&
         ThreadId == entry.ThreadId &&
         SourceId == entry.SourceId &&
         Message == entry.Message;
 }
Esempio n. 3
0
        public override void Log(LogEntry entry)
        {
            if(!ShouldBeLogged(entry))
            {
                return;
            }

            lock(sync)
            {
                if(isDisposed)
                {
                    return;
                }

                var type = entry.Type;
                var message = FormatLogEntry(entry);
                output.WriteLine(string.Format("{0:HH:mm:ss} [{1}] {2}", CustomDateTime.Now, type, message));
            }
        }
Esempio n. 4
0
        public int AddItem(LogEntry entry, bool scrollOnRefresh, int? limit = null)
        {
            int rowId;

            if(SqueezeEntries && entry.EqualsWithoutIdAndTime(lastLogEntry))
            {
                rowId = listStore.RowCount - 1;

                listStore.SetValue(rowId, idField, entry.Id);
                listStore.SetValue(rowId, textField, string.Format("{0} ({1})", entry.Message, ++lastLogEntryCounter));
                listStore.SetValue(rowId, timestampField, string.Format("{0:HH:mm:ss.ffff}", entry.Time));

                return rowId;
            }

            rowId = listStore.AddRow();

            listStore.SetValues(rowId, 
                imgField,       LogLevelToIcon(entry.Type),
                typeField,      entry.Type.ToString(),
                machineField,   entry.MachineName ?? string.Empty,
                objectField,    entry.ObjectName ?? string.Empty,
                textField,      entry.Message,
                timestampField, string.Format("{0:HH:mm:ss.ffff}", entry.Time),
                idField,        entry.Id);

            if(scrollOnRefresh || entry.Id == SelectedItemId)
            {
                SelectRow(rowId);
            }
            while (limit.HasValue && limit != 0 && listStore.RowCount > limit)
            {
                listStore.RemoveRow(0);
            }

            lastLogEntry = entry;
            lastLogEntryCounter = 1;
            return rowId;
        }
Esempio n. 5
0
        public override void Log(LogEntry entry)
        {
            if(!ShouldBeLogged(entry))
            {
                return;
            }

            var type = entry.Type;
            var changeColor = ColoringEnabled && output == Console.Out && type.Color.HasValue && !isRedirected;
            var message = FormatLogEntry(entry);
            
            lock(syncObject)
            {
                if(changeColor)
                {
                    Console.ForegroundColor = type.Color.Value;
                }
                string line;
                if(LogThreadId && entry.ThreadId != null)
                {
                    line = string.Format("{0:HH:mm:ss.ffff} [{1}] ({3}) {2}", CustomDateTime.Now, type, message, entry.ThreadId);
                }
                else
                {
                    line = string.Format("{0:HH:mm:ss.ffff} [{1}] {2}", CustomDateTime.Now, type, message);
                }
                if(output == Console.Out && !ReportRepeatingLines && 
                   lastMessage == message && lastMessageLinesCount != -1 && lastType == type && !isRedirected)
                {
                    try
                    {
                        counter++;
                        Console.CursorVisible = false;
                        Console.CursorTop = Math.Max(0, Console.CursorTop - lastMessageLinesCount);
                        // it can happen that console is resized between one and other write
                        // in case console is widened it would not erase previous messages
                        var realLine = string.Format("{0} ({1})", line, counter);
                        var currentLinesCount = GetMessageLinesCount(realLine);
                        var lineDiff = Math.Max(0, lastMessageLinesCount - currentLinesCount);
                        var width = Console.WindowWidth;
                        
                        Console.WriteLine(realLine);
                        lineDiff.Times(() => Console.WriteLine(Enumerable.Repeat<char>(' ', width - 1).ToArray()));
                        Console.CursorVisible = true;
                        Console.CursorTop = Math.Max(0, Console.CursorTop - lineDiff);
                        lastMessageLinesCount = GetMessageLinesCount(realLine);
                    }
                    catch(ArgumentOutOfRangeException)
                    {
                        // console was resized during computations
                        Console.Clear();
                        WriteNewLine(line);
                    }
                }
                else
                {
                    WriteNewLine(line);
                    lastMessage = message;
                    lastType = type;
                }
                if(changeColor)
                {
                    Console.ResetColor();
                }
            }
        }
Esempio n. 6
0
 public override void Log(LogEntry entry)
 {
     cache.Add(entry);
 }
Esempio n. 7
0
            public LogEntry ToLogEntry(Document doc)
            {
                LogLevel ll;
                LogLevel.TryParse(doc.Get(TypeFiledName), out ll);

                var result = new LogEntry(DateTime.FromBinary(long.Parse(doc.Get(TimeFiledName))), ll, doc.Get(MessageFieldName), int.Parse(doc.Get(SourceIdFieldName)));
                result.Id = ulong.Parse(doc.Get(IdFieldName));
                return result;
            }
Esempio n. 8
0
            public Document ToDocument(LogEntry entry)
            {
                machineField.SetValue(entry.MachineName ?? string.Empty);
                sourceField.SetValue(entry.ObjectName ?? string.Empty);
                idField.SetLongValue((long)entry.Id);
                typeField.SetValue(entry.Type.ToString());
                messageField.SetValue(entry.Message);
                timeField.SetLongValue(entry.Time.ToBinary());
                sourceIdField.SetIntValue(entry.SourceId);

                return document;
            }
Esempio n. 9
0
 private static bool TryDeserializeEntry(PrimitiveReader reader, out LogEntry entry)
 {
     var localEntry = (LogEntry)FormatterServices.GetUninitializedObject(typeof(LogEntry));
     try 
     {
         localEntry.Load(reader);
         entry = localEntry;
         return true;
     } 
     catch (EndOfStreamException)
     {
         // intentionally left blank
     }
     entry = null;
     return false;
 }
Esempio n. 10
0
 public void Add(LogEntry entry)
 {
     var copyOfWriter = currentWriter;
     Interlocked.Increment(ref copyOfWriter.ReferenceCounter);
     entry.Save(copyOfWriter.Writer);
     Interlocked.Decrement(ref copyOfWriter.ReferenceCounter);
 }
Esempio n. 11
0
        public int InsertItem(LogEntry entry, bool scrollOnRefresh, int? limit = null)
        {
            var rowId = listStore.InsertRowBefore(0);

            listStore.SetValues(rowId, 
                imgField,       LogLevelToIcon(entry.Type),
                typeField,      entry.Type.ToString(),
                machineField,   entry.MachineName ?? string.Empty,
                objectField,    entry.ObjectName ?? string.Empty,
                textField,      entry.Message,
                timestampField, string.Format("{0:HH:mm:ss.ffff}", entry.Time),
                idField,        entry.Id);

            if(scrollOnRefresh || entry.Id == SelectedItemId)
            {
                SelectRow(rowId);
            }
            while (limit.HasValue && limit != 0 && listStore.RowCount > limit)
            {
                listStore.RemoveRow(listStore.RowCount - 1);
            }

            return rowId;
        }
Esempio n. 12
0
 private void WriteLogEntryToBackends(LogEntry entry)
 {
     var allBackends = Logger.backends.Items;
     for(var i = 0; i < allBackends.Length; i++)
     {
         allBackends[i].Log(entry);
     }
 }
Esempio n. 13
0
            public void ObjectInnerLog(object o, LogLevel type, string message, params object[] args)
            {
                int sourceId = (o == null) ? -1 : GetOrCreateSourceId(o);
                if(args.Length > 0)
                {
                    message = string.Format(message, args);
                }

                var entry = new LogEntry(CustomDateTime.Now, type, message, sourceId, Thread.CurrentThread.ManagedThreadId);

                if(useSynchronousLogging)
                {
                    lock(synchronousLoggingLock)
                    {
                        entry.Id = Logger.nextEntryId++;
                        WriteLogEntryToBackends(entry);
                    }
                }
                else
                {
                    entries.Add(entry);
                }
            }
Esempio n. 14
0
            public void ObjectInnerLog(object o, LogLevel type, string message, params object[] args)
            {
                int sourceId = (o == null) ? -1 : GetOrCreateSourceId(o);
                if(args.Length > 0)
                {
                    message = string.Format(message, args);
                }

                var entry = new LogEntry(CustomDateTime.Now, type, message, sourceId, Thread.CurrentThread.ManagedThreadId);
                entries.Add(entry);
            }