public void OnContextIoCommandEnd(IProcess process, int uid, IoCommandKind kind, int?affectedDataCount, Exception ex)
    {
        Counters.TryGetValue(kind, out var counter);
        if (counter == null)
        {
            Counters[kind] = counter = new IoCommandCounter();
        }

        counter.InvocationCount++;

        if (affectedDataCount != null)
        {
            var cnt = (counter.AffectedDataCount ?? 0) + affectedDataCount.Value;
            counter.AffectedDataCount = cnt;
        }
    }
Beispiel #2
0
        public void OnContextIoCommandEnd(IProcess process, int uid, IoCommandKind kind, int?affectedDataCount, Exception ex)
        {
            IoCommandCounters.TryGetValue(kind, out var counter);
            if (counter == null)
            {
                IoCommandCounters[kind] = counter = new IoCommandCounter();
            }

            counter.InvocationCount++;

            if (affectedDataCount != null)
            {
                var cnt = (counter.AffectedDataCount ?? 0) + affectedDataCount.Value;
                counter.AffectedDataCount = cnt;
            }

            if (ParentContext is ExecutionContext pec)
            {
                pec.IoCommandCounters.TryGetValue(kind, out counter);
                if (counter == null)
                {
                    pec.IoCommandCounters[kind] = counter = new IoCommandCounter();
                }

                counter.InvocationCount++;

                if (affectedDataCount != null)
                {
                    var cnt = (counter.AffectedDataCount ?? 0) + affectedDataCount.Value;
                    counter.AffectedDataCount = cnt;
                }
            }

            if (ex != null)
            {
                var sb     = new StringBuilder();
                var values = new List <object>();

                if (PluginName != null)
                {
                    if (process != null)
                    {
                        if (process.Topic?.Name != null)
                        {
                            sb.Append("[{Module}/{Plugin}/{ActiveProcess}/{ActiveTopic}] ");
                            values.Add(ModuleName);
                            values.Add(PluginName);
                            values.Add(process.Name);
                            values.Add(process.Topic?.Name);
                        }
                        else
                        {
                            sb.Append("[{Module}/{Plugin}/{ActiveProcess}] ");
                            values.Add(ModuleName);
                            values.Add(PluginName);
                            values.Add(process.Name);
                        }
                    }
                    else
                    {
                        sb.Append("[{Module}/{Plugin}] ");
                        values.Add(ModuleName);
                        values.Add(PluginName);
                    }
                }

                sb.Append("{IoCommandUid}/EXCEPTION, {ErrorMessage}");
                values.Add(uid);
                values.Add(ex.FormatExceptionWithDetails());

                _commandContext.IoLogger.Write(LogEventLevel.Error, sb.ToString(), values.ToArray());
            }

            foreach (var listener in CustomListeners)
            {
                listener.OnContextIoCommandEnd(process, uid, kind, affectedDataCount, ex);
            }
        }