示例#1
0
 /// <summary>
 /// Signals the launch of one or more dependent activities by emitting a log line that describes the token.
 /// The token must have been created by <see cref="CreateToken"/> or <see cref="CreateTokenWithTopic"/> with a true delayedLaunch parameter
 /// otherwise an <see cref="InvalidOperationException"/> is thrown.
 /// </summary>
 /// <param name="token">Dependent token.</param>
 public void Launch(ActivityMonitor.DependentToken token)
 {
     if (token.DelayedLaunchMessage == null)
     {
         throw new InvalidOperationException(Impl.ActivityMonitorResources.ActivityMonitorDependentTokenMustBeDelayedLaunch);
     }
     _monitor.UnfilteredLog(ActivityMonitor.Tags.CreateDependentActivity, LogLevel.Info, token.DelayedLaunchMessage, _monitor.NextLogTime(), null, _fileName, _lineNumber);
 }
示例#2
0
 public static void SendLine(this IActivityMonitor @this, LogLevel level, string text, Exception ex, [CallerFilePath] string fileName = null, [CallerLineNumber] int lineNumber = 0)
 {
     if (@this.ShouldLogLine(level, fileName, lineNumber))
     {
         @this.UnfilteredLog(null, level | LogLevel.IsFiltered, text, @this.NextLogTime(), ex, fileName, lineNumber);
     }
 }
            internal static DependentToken CreateWithMonitorTopic(IActivityMonitor m, bool launchActivity, out string msg)
            {
                msg = launchActivity ? _prefixLaunch : _prefixCreate;
                DependentToken t = new DependentToken(((IUniqueId)m).UniqueId, m.NextLogTime(), m.Topic);

                msg += '.';
                return(t);
            }
            static internal IDisposable Start(ActivityMonitor.DependentToken token, IActivityMonitor monitor, string fileName, int lineNumber)
            {
                string msg = token.FormatStartMessage();

                if (token.Topic != null)
                {
                    string currentTopic = token.Topic;
                    monitor.SetTopic(token.Topic, fileName, lineNumber);
                    var g = monitor.UnfilteredOpenGroup(ActivityMonitor.Tags.StartDependentActivity, LogLevel.Info, null, msg, monitor.NextLogTime(), null, fileName, lineNumber);
                    return(Util.CreateDisposableAction(() => { g.Dispose(); monitor.SetTopic(currentTopic, fileName, lineNumber); }));
                }
                return(monitor.UnfilteredOpenGroup(ActivityMonitor.Tags.StartDependentActivity, LogLevel.Info, null, msg, monitor.NextLogTime(), null, fileName, lineNumber));
            }
 internal static DependentToken CreateWithDependentTopic(IActivityMonitor m, bool launchActivity, string dependentTopic, out string msg)
 {
     msg = AppendTopic(launchActivity ? _prefixLaunchWithTopic : _prefixCreateWithTopic, dependentTopic);
     return(new DependentToken(((IUniqueId)m).UniqueId, m.NextLogTime(), dependentTopic));
 }
示例#6
0
        bool DumpGitFolders(IActivityMonitor m, IEnumerable <GitFolder> gitFolders)
        {
            bool      isLogFilterDefault = false;
            LogFilter final = m.ActualFilter;

            if (final == LogFilter.Undefined)
            {
                final = ActivityMonitor.DefaultFilter;
                isLogFilterDefault = true;
            }
            var msg = $"Monitor filters: User:'******' => Final:'{final}'{(isLogFilterDefault ? "(AppDomain's default)" : "")}.";

            m.UnfilteredLog(ActivityMonitor.Tags.Empty, LogLevel.Info, msg, m.NextLogTime(), null);

            int  gitFoldersCount    = 0;
            bool hasPluginInitError = false;
            var  dirty = new List <string>();

            foreach (var git in gitFolders)
            {
                ++gitFoldersCount;
                string commitAhead = git.Head.AheadOriginCommitCount != null ? $"{git.Head.AheadOriginCommitCount} commits ahead origin" : "Untracked";
                using (m.OpenInfo($"{git.SubPath} - branch: {git.CurrentBranchName} ({commitAhead})."))
                {
                    string pluginInfo;
                    if (!git.EnsureCurrentBranchPlugins(m))
                    {
                        hasPluginInitError = true;
                        pluginInfo         = "Plugin initialization error.";
                    }
                    else
                    {
                        pluginInfo = $"({git.PluginManager.BranchPlugins[git.CurrentBranchName].Count} plugins)";
                    }

                    if (git.CheckCleanCommit(m))
                    {
                        m.CloseGroup("Up-to-date. " + pluginInfo);
                    }
                    else
                    {
                        dirty.Add(git.SubPath);
                        m.CloseGroup("Dirty. " + pluginInfo);
                    }
                }
            }
            if (gitFoldersCount == 0)
            {
                m.Error("No git folder found.");
            }
            else
            {
                m.CloseGroup($"{dirty.Count} dirty (out of {gitFoldersCount}).");
                if (dirty.Count > 0)
                {
                    m.Info($"Dirty: {dirty.Concatenate()}");
                }
                var byActiveBranch = gitFolders.GroupBy(g => g.CurrentBranchName);
                if (byActiveBranch.Count() > 1)
                {
                    using (m.OpenWarn($"{byActiveBranch.Count()} different branches:"))
                    {
                        foreach (var b in byActiveBranch)
                        {
                            using (m.OpenWarn($"Branch '{b.Key}':"))
                            {
                                m.Warn(b.Select(g => g.SubPath.Path).Concatenate());
                            }
                        }
                    }
                }
                else
                {
                    m.Info($"All {gitFoldersCount} git folders are on '{byActiveBranch.First().Key}' branch.");
                }

                if (hasPluginInitError)
                {
                    m.Error("At least one git folder is unable to initialize its plugins.");
                }
            }
            return(!hasPluginInitError);
        }
示例#7
0
 public static IDisposable OpenGroup(this IActivityMonitor @this, LogLevel level, string text, Exception ex, [CallerFilePath] string fileName = null, [CallerLineNumber] int lineNumber = 0)
 {
     if (@this.ShouldLogGroup(level, fileName, lineNumber))
     {
         return(@this.UnfilteredOpenGroup(new ActivityMonitorGroupData(level | LogLevel.IsFiltered, null, text, @this.NextLogTime(), ex, null, fileName, lineNumber)));
     }
     return(@this.UnfilteredOpenGroup(new ActivityMonitorGroupData()));
 }
 static internal IDisposable Start( ActivityMonitor.DependentToken token, IActivityMonitor monitor, string fileName, int lineNumber )
 {
     string msg = token.FormatStartMessage();
     if( token.Topic != null )
     {
         string currentTopic = token.Topic;
         monitor.SetTopic( token.Topic, fileName, lineNumber );
         var g = monitor.UnfilteredOpenGroup( ActivityMonitor.Tags.StartDependentActivity, LogLevel.Info, null, msg, monitor.NextLogTime(), null, fileName, lineNumber );
         return Util.CreateDisposableAction( () => { g.Dispose(); monitor.SetTopic( currentTopic, fileName, lineNumber ); } );
     }
     return monitor.UnfilteredOpenGroup( ActivityMonitor.Tags.StartDependentActivity, LogLevel.Info, null, msg, monitor.NextLogTime(), null, fileName, lineNumber );
 }
 internal static DependentToken CreateWithDependentTopic( IActivityMonitor m, bool launchActivity, string dependentTopic, out string msg )
 {
     msg = AppendTopic( launchActivity ? _prefixLaunchWithTopic : _prefixCreateWithTopic, dependentTopic );
     return new DependentToken( ((IUniqueId)m).UniqueId, m.NextLogTime(), dependentTopic );
 }
 internal static DependentToken CreateWithMonitorTopic( IActivityMonitor m, bool launchActivity, out string msg )
 {
     msg = launchActivity ? _prefixLaunch : _prefixCreate;
     DependentToken t = new DependentToken( ((IUniqueId)m).UniqueId, m.NextLogTime(), m.Topic );
     msg += '.';
     return t;
 }
 internal void InitializeAndSend(Exception exception, CKTrait tags, string text)
 {
     Debug.Assert(!IsRejected);
     Initialize(text, exception, tags, _monitor.NextLogTime());
     _monitor.UnfilteredLog(this);
 }
示例#12
0
 static void DefaultOnRequestError(HttpContext ctx, IActivityMonitor m, Exception ex)
 {
     m.UnfilteredLog(null, LogLevel.Fatal, ex.Message, m.NextLogTime(), ex);
     ctx.Response.StatusCode = StatusCodes.Status500InternalServerError;
 }
 internal IDisposableGroup InitializeAndSend(Exception exception, CKTrait tags, string text)
 {
     Debug.Assert(!IsRejected);
     Initialize(text, exception, tags, Monitor.NextLogTime());
     return(Monitor.UnfilteredOpenGroup(this));
 }