예제 #1
0
 public void OnContextIoCommandStart(int uid, IoCommandKind kind, string location, string path, IProcess process, int?timeoutSeconds, string command, string transactionId, Func <IEnumerable <KeyValuePair <string, object> > > argumentListGetter, string message, params object[] messageArgs)
 {
     SendDiagnostics(DiagnosticsEventKind.IoCommandStart, writer =>
     {
         writer.Write7BitEncodedInt(uid);
         writer.Write7BitEncodedInt(process.InvocationInfo.InvocationUid);
         writer.Write((byte)kind);
         writer.Write7BitEncodedInt(GetTextDictionaryKey(location));
         writer.Write7BitEncodedInt(GetTextDictionaryKey(path));
         writer.WriteNullable(timeoutSeconds);
         writer.WriteNullable(command);
         writer.Write7BitEncodedInt(GetTextDictionaryKey(transactionId));
         var arguments = argumentListGetter?.Invoke()?.ToArray();
         if (arguments?.Length > 0)
         {
             writer.Write7BitEncodedInt(arguments.Length);
             foreach (var kvp in arguments)
             {
                 writer.Write7BitEncodedInt(GetTextDictionaryKey(kvp.Key));
                 writer.WriteObject(kvp.Value);
             }
         }
         else
         {
             writer.Write7BitEncodedInt(0);
         }
     });
 }
예제 #2
0
 public void RegisterIoCommandFailed(IProcess process, IoCommandKind kind, int uid, int?affectedDataCount, Exception exception)
 {
     foreach (var listener in Listeners)
     {
         listener.OnContextIoCommandEnd(process, uid, kind, affectedDataCount, exception);
     }
 }
예제 #3
0
 public NamedStream(string name, Stream stream, int ioCommandUid, IoCommandKind ioCommandKind)
 {
     Name          = name;
     Stream        = stream;
     IoCommandUid  = ioCommandUid;
     IoCommandKind = ioCommandKind;
 }
예제 #4
0
 public void RegisterIoCommandSuccess(IProcess process, IoCommandKind kind, int uid, int?affectedDataCount)
 {
     foreach (var listener in Listeners)
     {
         listener.OnContextIoCommandEnd(process, uid, kind, affectedDataCount, null);
     }
 }
예제 #5
0
 public void OnContextIoCommandEnd(IProcess process, int uid, IoCommandKind kind, int?affectedDataCount, Exception ex)
 {
     SendDiagnostics(DiagnosticsEventKind.IoCommandEnd, writer =>
     {
         writer.Write7BitEncodedInt(uid);
         writer.WriteNullable(affectedDataCount);
         writer.WriteNullable(ex?.FormatExceptionWithDetails());
     });
 }
예제 #6
0
        public int RegisterIoCommandStart(IProcess process, IoCommandKind kind, string location, string path, int?timeoutSeconds, string command, string transactionId, Func <IEnumerable <KeyValuePair <string, object> > > argumentListGetter, string message, params object[] messageArgs)
        {
            var uid = Interlocked.Increment(ref _nextIoCommandUid);

            foreach (var listener in Listeners)
            {
                listener.OnContextIoCommandStart(uid, kind, location, path, process, timeoutSeconds, command, transactionId, argumentListGetter, message, messageArgs);
            }

            return(uid);
        }
        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;
            }
        }
예제 #8
0
 public NamedSink(string name, Stream stream, int ioCommandUid, IoCommandKind ioCommandKind, int sinkUid)
     : base(name, stream, ioCommandUid, ioCommandKind)
 {
     SinkUid = sinkUid;
 }
 public void OnContextIoCommandStart(int uid, IoCommandKind kind, string location, string path, IProcess process, int?timeoutSeconds, string command, string transactionId, Func <IEnumerable <KeyValuePair <string, object> > > argumentListGetter, string message, params object[] messageArgs)
 {
 }
예제 #10
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);
            }
        }
예제 #11
0
        public void OnContextIoCommandStart(int uid, IoCommandKind kind, string location, string path, IProcess process, int?timeoutSeconds, string command, string transactionId, Func <IEnumerable <KeyValuePair <string, object> > > argumentListGetter, string message, params object[] messageArgs)
        {
            if (message != 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);
                    }
                }

                if (transactionId != null)
                {
                    sb.Append("/{ActiveTransaction}/ ");
                    values.Add(transactionId);
                }

                sb.Append("{IoCommandUid}/{IoCommandKind}");
                values.Add(uid);
                values.Add(kind.ToString());

                if (location != null)
                {
                    sb.Append(", location: {IoCommandTarget}");
                    values.Add(location);
                }

                if (path != null)
                {
                    sb.Append(", path: {IoCommandTargetPath}");
                    values.Add(path);
                }

                if (timeoutSeconds != null)
                {
                    sb.Append(", timeout: {IoCommandTimeout}");
                    values.Add(timeoutSeconds);
                }

                sb.Append(", message: ").Append(message);
                if (messageArgs != null)
                {
                    values.AddRange(messageArgs);
                }

                if (command != null)
                {
                    sb.Append(", command: {IoCommand}");
                    values.Add(command);
                }

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

            foreach (var listener in CustomListeners)
            {
                listener.OnContextIoCommandStart(uid, kind, location, path, process, timeoutSeconds, command, transactionId, argumentListGetter, message, messageArgs);
            }
        }