コード例 #1
0
 public void DebugFormat(string format, params object[] args)
 {
     if (_runtime == null) return;
     if (_runtime.Invoke() == RuntimePolicy.Off) return;
     if (format == null) return;
     if (!LoggerFactory.LogRequest()) return;
     var item = new LogStatistic(null, null)
                    {
                        ConnectionNotification = string.Format(format.Trim().UppercaseFirst(), args).ToUpper()
                    };
     Log(item);
 }
コード例 #2
0
 public void Debug(object message)
 {
     if (_runtime == null) return;
     if (_runtime.Invoke() == RuntimePolicy.Off) return;
     if (message == null) return;
     if (!LoggerFactory.LogRequest()) return;
     if (!message.ToString().ToLower().Trim().StartsWith(TargetMessage)) return;
     if (!LoggerFactory.LogRequest()) return;
     var item = new LogStatistic(null, null)
                    {
                        LoadNotification =
                            message.ToString().Replace(TargetMessage, string.Empty).Trim().UppercaseFirst()
                    };
     Log(item);
 }
コード例 #3
0
 public void Debug(object message)
 {
     if (_runtime == null) return;
     if (_runtime.Invoke() == RuntimePolicy.Off) return;
     if (message == null) return;
     if (!LoggerFactory.LogRequest()) return;
     var stackFrames = new System.Diagnostics.StackTrace().GetFrames();
     var methods = new List<MethodBase>();
     if (stackFrames != null)
     {
         foreach (var frame in stackFrames)
         {
             var meth = frame.GetMethod();
             var type = meth.DeclaringType;
             // ReSharper disable ConditionIsAlwaysTrueOrFalse
             //this can happen for emitted types
             if (type != null)
             // ReSharper restore ConditionIsAlwaysTrueOrFalse
             {
                 var assem = type.Assembly;
                 if (Equals(assem, _thisAssem)) continue;
                 if (Equals(assem, _nhAssem)) continue;
                 if (Equals(assem, _glimpseAssem)) continue;    
             }
             methods.Add(frame.GetMethod());
         }
     }
     // ReSharper disable ConditionIsAlwaysTrueOrFalse
     var frames = methods
         .Select(method => string.Format("{0} -> {1}", (method.DeclaringType == null) ? "DYNAMIC" : method.DeclaringType.ToString(), method))
         .ToList();
     // ReSharper restore ConditionIsAlwaysTrueOrFalse
     var item = new LogStatistic(null, null)
                    {
                        Sql = message.ToString(),
                        StackFrames = frames,
                        ExecutionType = (methods.Count == 0)
                                            ? null
                                            : (methods[0].DeclaringType == null)
                                                  ? "Object"
                                                  : methods[0].DeclaringType.Name,
                        ExecutionMethod = (methods.Count == 0) ? null : methods[0].Name,
                    };
     SqlCommandExecuted(item);
     Log(item);
 }
コード例 #4
0
 public void Debug(object message)
 {
     if (_runtime == null) return;
     if (_runtime.Invoke() == RuntimePolicy.Off) return;
     if (message == null) return;
     if (!LoggerFactory.LogRequest()) return;
     var timestamp = DateTime.Now;
     var item = new LogStatistic(null, null)
                    {
                        TransactionNotification =
                            string.Format("{0}{1}", message.ToString().Trim().UppercaseFirst(),
                                          string.Format(" @ {0}.{1}.{2}.{3}",
                                                        timestamp.Hour.ToString(CultureInfo.InvariantCulture)
                                                                 .PadLeft(2, '0'),
                                                        timestamp.Minute.ToString(CultureInfo.InvariantCulture)
                                                                 .PadLeft(2, '0'),
                                                        timestamp.Second.ToString(CultureInfo.InvariantCulture)
                                                                 .PadLeft(2, '0'),
                                                        timestamp.Millisecond.ToString(
                                                            CultureInfo.InvariantCulture).PadLeft(3, '0')))
                    };
     Log(item);
 }
コード例 #5
0
 static void Log(LogStatistic logStatistic)
 {
     if (_messageBroker == null) return;
     _messageBroker.Publish(logStatistic);
 }
コード例 #6
0
        static void SqlCommandExecuted(LogStatistic logStatistic)
        {
            if (_timerStrategy == null) return;
            var timer = _timerStrategy.Invoke();
            if (timer == null) return;
            var point = timer.Point();

            var pointTimelineMessage = new NHibernateTimelineMessage
                                           {
                                               Duration = point.Duration,
                                               Offset = point.Offset,
                                               StartTime = point.StartTime,
                                               EventName = string.Format("{0}:{1}", logStatistic.ExecutionType, logStatistic.ExecutionMethod),
                                               EventSubText = logStatistic.Id.ToString()
                                           };
          _messageBroker.Publish(pointTimelineMessage);
        }
コード例 #7
0
        public void Debug(object message)
        {
            if (_runtime == null) return;
            if (_runtime.Invoke() == RuntimePolicy.Off) return;
            if (message == null) return;
            if (!LoggerFactory.LogRequest()) return;
            var stackFrames = new StackTrace(true).GetFrames();
            var methods = new List<MethodBase>();
            var stackTrace = new List<StackFrame>();
            if (stackFrames != null)
            {
                foreach (var frame in stackFrames)
                {
                    var meth = frame.GetMethod();
                    var type = meth.DeclaringType;
                    // ReSharper disable ConditionIsAlwaysTrueOrFalse
                    //this can happen for emitted types
                    if (type != null)
                    // ReSharper restore ConditionIsAlwaysTrueOrFalse
                    {
                        var assem = type.Assembly;
                        if (Equals(assem, _thisAssem)) continue;
                        if (Equals(assem, _nhAssem)) continue;
                        if (Equals(assem, _glimpseAssem)) continue;
                    }
                    methods.Add(meth);
                    stackTrace.Add(frame);
                }
            }
            // ReSharper disable ConditionIsAlwaysTrueOrFalse
            var frames = stackTrace
                .Select(frame =>
                {
                    var method = frame.GetMethod();
                    var fileName = frame.GetFileName();
                    var hasFileName = fileName != null;
                    var displayPrefix = hasFileName ? "[#] " : ""; // visual cue that the frame has file info if expanded
                    var displaySuffix = hasFileName ?
                        string.Format(" @ {0}, line {1}, column {2}",
                            fileName,
                            frame.GetFileLineNumber(),
                            frame.GetFileColumnNumber()) :
                        "";

                    return string.Format(displayPrefix + "{0} -> {1}" + displaySuffix,
                        (method.DeclaringType == null) ? "DYNAMIC" : method.DeclaringType.ToString(), method);
                })
                .ToList();
            // ReSharper restore ConditionIsAlwaysTrueOrFalse
            var item = new LogStatistic(null, null)
                           {
                               Sql = message.ToString(),
                               StackFrames = frames,
                               ExecutionType = (methods.Count == 0)
                                                   ? null
                                                   : (methods[0].DeclaringType == null)
                                                         ? "Object"
                                                         : methods[0].DeclaringType.Name,
                               ExecutionMethod = (methods.Count == 0) ? null : methods[0].Name,
                           };
            SqlCommandExecuted(item);
            Log(item);
        }