Example #1
0
        public void WithInnerExceptions()
        {
            Exception e = ThrowExceptionWithInner();
            var       d = CKExceptionData.CreateFrom(e);

            CheckSimpleExceptionData(d, s => s == "Outer", true);
            CheckSimpleExceptionData(d.InnerException, s => s == "Inner", false);
            var backToEx   = new CKException(d);
            var backToData = CKExceptionData.CreateFrom(backToEx);

            CheckSimpleExceptionData(backToData, s => s == "Outer", true);
            CheckSimpleExceptionData(backToData.InnerException, s => s == "Inner", false);
        }
            /// <summary>
            /// Replays this monitor's content into another monitor.
            /// </summary>
            /// <param name="replay">The target monitor. Can not be null.</param>
            /// <param name="m">Optional monitor (nothing is logged when null).</param>
            public void Replay(IActivityMonitor replay, IActivityMonitor m = null)
            {
                using (m != null ? m.OpenGroup(LogLevel.Info, string.Format("Replaying activity from '{0}'.", MonitorId), null) : null)
                {
                    int nbMissing = 0;
                    int nbTotal   = 0;
                    using (var page = ReadFirstPage(1024))
                    {
                        foreach (ParentedLogEntry e in page.Entries)
                        {
                            ++nbTotal;
                            LogLevel level = e.Entry.LogLevel;
                            if (e.IsMissing)
                            {
                                ++nbMissing;
                                level = LogLevel.Trace;
                            }
                            switch (e.Entry.LogType)
                            {
                            case LogEntryType.Line:
                                replay.UnfilteredLog(e.Entry.Tags, level, e.Entry.Text, e.Entry.LogTime, CKException.CreateFrom(e.Entry.Exception), e.Entry.FileName, e.Entry.LineNumber);
                                break;

                            case LogEntryType.OpenGroup:
                                replay.UnfilteredOpenGroup(e.Entry.Tags, level, null, e.Entry.Text, e.Entry.LogTime, CKException.CreateFrom(e.Entry.Exception), e.Entry.FileName, e.Entry.LineNumber);
                                break;

                            case LogEntryType.CloseGroup:
                                replay.CloseGroup(e.Entry.LogTime, e.Entry.Conclusions);
                                break;
                            }
                        }
                        page.ForwardPage();
                    }
                    if (m != null)
                    {
                        m.CloseGroup(String.Format("Replayed {0} entries ({1} missing).", nbTotal, nbMissing));
                    }
                }
            }
Example #3
0
            /// <summary>
            /// Replays this monitor's content into another monitor.
            /// </summary>
            /// <param name="replay">The target monitor. Can not be null.</param>
            /// <param name="monitor">Optional monitor (nothing is logged when null).</param>
            public void Replay(IActivityMonitor replay, IActivityMonitor?monitor = null)
            {
                using (monitor?.OpenInfo($"Replaying activity from '{MonitorId}'."))
                {
                    int nbMissing = 0;
                    int nbTotal   = 0;
                    using (var page = ReadFirstPage(1024))
                    {
                        foreach (ParentedLogEntry e in page.Entries)
                        {
                            ++nbTotal;
                            LogLevel level = e.Entry.LogLevel;
                            if (e.IsMissing)
                            {
                                ++nbMissing;
                                level = LogLevel.Trace;
                            }
                            switch (e.Entry.LogType)
                            {
                            case LogEntryType.Line:
                                var d = new ActivityMonitorLogData(level, e.Entry.Tags, e.Entry.Text, CKException.CreateFrom(e.Entry.Exception), e.Entry.FileName, e.Entry.LineNumber);
                                d.SetExplicitLogTime(e.Entry.LogTime);
                                replay.UnfilteredLog(ref d);
                                break;

                            case LogEntryType.OpenGroup:
                                d = new ActivityMonitorLogData(level, e.Entry.Tags, e.Entry.Text, CKException.CreateFrom(e.Entry.Exception), e.Entry.FileName, e.Entry.LineNumber);
                                d.SetExplicitLogTime(e.Entry.LogTime);
                                replay.UnfilteredOpenGroup(ref d);
                                break;

                            case LogEntryType.CloseGroup:
                                replay.CloseGroup(e.Entry.Conclusions, e.Entry.LogTime);
                                break;
                            }
                        }
                        page.ForwardPage();
                    }
                    monitor?.CloseGroup($"Replayed {nbTotal} entries ({nbMissing} missing).");
                }
            }
        void Run()
        {
            try
            {
                int streamVersion = _reader.ReadInt32();
                if (_interProcess)
                {
                    _server.DisposeLocalCopyOfClientHandle();
                }
                for (; ;)
                {
                    var e = LogEntry.Read(_reader, streamVersion, out bool badEndOfStream);
                    if (e == null || badEndOfStream)
                    {
                        _endFlag = badEndOfStream ? LogReceiverEndStatus.MissingEndMarker : LogReceiverEndStatus.Normal;
                        break;
                    }
                    switch (e.LogType)
                    {
                    case LogEntryType.Line:
                    {
                        if (_monitor.ShouldLogLine(e.LogLevel, e.Tags, out var finalTags))
                        {
                            var d = new ActivityMonitorLogData(e.LogLevel | LogLevel.IsFiltered, finalTags, e.Text, CKException.CreateFrom(e.Exception), e.FileName, e.LineNumber);
                            d.SetExplicitLogTime(e.LogTime);
                            _monitor.UnfilteredLog(ref d);
                        }
                        break;
                    }

                    case LogEntryType.OpenGroup:
                    {
                        ActivityMonitorLogData d;
                        if (_monitor.ShouldLogLine(e.LogLevel, e.Tags, out var finalTags))
                        {
                            d = new ActivityMonitorLogData(e.LogLevel | LogLevel.IsFiltered, finalTags, e.Text, CKException.CreateFrom(e.Exception), e.FileName, e.LineNumber);
                            d.SetExplicitLogTime(e.LogTime);
                        }
                        else
                        {
                            d = default;
                        }
                        _monitor.UnfilteredOpenGroup(ref d);
                    }

                    break;

                    case LogEntryType.CloseGroup:
                        _monitor.CloseGroup(e.Conclusions, e.LogTime);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                _endFlag = LogReceiverEndStatus.Error;
                _monitor.UnfilteredLog(LogLevel.Fatal, null, "While receiving pipe logs.", ex);
            }
        }