Example #1
0
        private void PublishByType(Message message, Type type)
        {
            List <IMessageHandler> handlers;

            if (!_typeHash.TryGetValue(type, out handlers))
            {
                return;
            }

            for (int i = 0, n = handlers.Count; i < n; ++i)
            {
                var handler = handlers[i];
                if (_watchSlowMsg)
                {
                    var start = DateTime.UtcNow;

                    handler.TryHandle(message);

                    var elapsed = DateTime.UtcNow - start;
                    if (elapsed > _slowMsgThreshold)
                    {
                        Log.Verbose("SLOW BUS MSG [{bus}]: {message} - {elapsed}ms. Handler: {handler}.",
                                    Name, message.GetType().Name, (int)elapsed.TotalMilliseconds, handler.HandlerName);
                    }
                }
                else
                {
                    handler.TryHandle(message);
                }
            }
        }
Example #2
0
 private PerformanceCounter CreatePerfCounter(string category, string counter, string instance = null)
 {
     try {
         return(string.IsNullOrEmpty(instance)
                                 ? new PerformanceCounter(category, counter)
                                 : new PerformanceCounter(category, counter, instance));
     } catch (Exception ex) {
         _log.Verbose(
             "Could not create performance counter: category='{category}', counter='{counter}', instance='{instance}'. Error: {e}",
             category, counter, instance ?? string.Empty, ex.Message);
         return(null);
     }
 }