public override void OnExit(MethodExecutionArgs args)
        {
            _performanceTimer.StopTime();

            var    totalTime  = _performanceTimer.ElapsedTime();
            var    aspectName = this.GetType().Name;
            string message;
            string jsonLogDetail;

            switch (_performanceType)
            {
            case PerformanceType.Info:

                if (!_logService.IsEnabledFor(LoggingEventType.Information))
                {
                    return;
                }

                message = $"The method runtime took {totalTime} seconds.";

                jsonLogDetail = args.LogMethodDetail(message, aspectName).ToJson();

                _logService.InformationLog(jsonLogDetail);
                break;

            case PerformanceType.Warning:

                if (!_logService.IsEnabledFor(LoggingEventType.Warning))
                {
                    return;
                }

                if (totalTime > _interval)
                {
                    message =
                        $"The specified runtime is {_interval} seconds, It took {totalTime} seconds. Method runtime and specified runtime difference {totalTime - _interval} seconds.";
                    jsonLogDetail = args.LogMethodDetail(message, aspectName).ToJson();
                    _logService.WarningLog(jsonLogDetail);
                }

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        public override void OnException(MethodExecutionArgs args)
        {
            if (!_logService.IsEnabledFor(LoggingEventType.Error))
            {
                return;
            }

            var aspectName    = this.GetType().Name;
            var jsonLogDetail = args.LogMethodDetail(null, aspectName).ToJson();

            _logService.ErrorWithExceptionLog(jsonLogDetail, args.Exception);
        }
Esempio n. 3
0
        public override void OnEntry(MethodExecutionArgs args)
        {
            var aspectName    = GetType().Name;
            var jsonLogDetail = JsonConvert.SerializeObject(args.LogMethodDetail(null, aspectName));

            switch (_loggingEventType)
            {
            case LoggingEventType.Debug:
                if (_logService.IsEnabledFor(LoggingEventType.Debug))
                {
                    _logService.DebugLog(jsonLogDetail);
                }
                break;

            case LoggingEventType.Information:
                if (_logService.IsEnabledFor(LoggingEventType.Information))
                {
                    _logService.InformationLog(jsonLogDetail);
                }
                break;

            case LoggingEventType.Warning:
                if (_logService.IsEnabledFor(LoggingEventType.Warning))
                {
                    _logService.WarningLog(jsonLogDetail);
                }
                break;

            case LoggingEventType.Error:
                if (_logService.IsEnabledFor(LoggingEventType.Error))
                {
                    _logService.ErrorLog(jsonLogDetail);
                }
                break;

            case LoggingEventType.Fatal:
                if (_logService.IsEnabledFor(LoggingEventType.Fatal))
                {
                    _logService.FatalLog(jsonLogDetail);
                }
                break;

            case LoggingEventType.Trace:
                if (_logService.IsEnabledFor(LoggingEventType.Trace))
                {
                    _logService.TraceLog(jsonLogDetail);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }