Example #1
0
        /// <summary>
        /// Writes the log event to the underlying logger.
        /// </summary>
        /// <param name="callerMemberName">The method or property name of the caller to the method. This is set at by the compiler.</param>
        /// <param name="callerFilePath">The full path of the source file that contains the caller. This is set at by the compiler.</param>
        /// <param name="callerLineNumber">The line number in the source file at which the method is called. This is set at by the compiler.</param>
        public void Write(
            [CallerMemberName] string callerMemberName = null,
            [CallerFilePath] string callerFilePath     = null,
            [CallerLineNumber] int callerLineNumber    = 0)
        {
            if (!_logger.IsEnabled(_logEvent.Level))
            {
                return;
            }

            // TODO NLog ver. 5 - Remove these properties
            if (callerMemberName != null)
            {
                Property("CallerMemberName", callerMemberName);
            }
            if (callerFilePath != null)
            {
                Property("CallerFilePath", callerFilePath);
            }
            if (callerLineNumber != 0)
            {
                Property("CallerLineNumber", callerLineNumber);
            }

            _logEvent.SetCallerInfo(null, callerMemberName, callerFilePath, callerLineNumber);

            _logger.Log(_logEvent);
        }
Example #2
0
 private void SetCallerInfo(string callerMethodName, string callerFilePath, int callerLineNumber)
 {
     if (callerMethodName != null || callerFilePath != null || callerLineNumber != 0)
     {
         logEvent.SetCallerInfo(null, callerMethodName, callerFilePath, callerLineNumber);
     }
 }
Example #3
0
        private static void LogMethodEvent(string logEvent, string codeBase
                                           , ILogger _logger, string invocationTarget
                                           , string methodName, Exception ex = null)
        {
            var logMethodEvent = new LogEventInfo();

            if (logEvent == "MethodStart")
            {
                logMethodEvent = LogEventInfo.Create(LogLevel.Info,
                                                     invocationTarget,
                                                     "Executing Method - " + methodName
                                                     + " | Class - " + invocationTarget);
            }
            else if (logEvent == "MethodEnd")
            {
                logMethodEvent = LogEventInfo.Create(LogLevel.Info, invocationTarget,
                                                     "Successfuly Executed Method - " + methodName
                                                     + " | Class - " + invocationTarget);
            }
            else if (logEvent == "MethodError")
            {
                logMethodEvent = LogEventInfo.Create(LogLevel.Error, invocationTarget,
                                                     ex, null, "Error Occured on Executing Method - " + methodName
                                                     + " | Class - " + invocationTarget +
                                                     " | Trace - " + ex.InnerException + ex.Message + ex.StackTrace);
            }

            logMethodEvent.SetCallerInfo(invocationTarget,
                                         methodName + " - ",
                                         codeBase, 0);
            _logger.Log(logMethodEvent);
        }
Example #4
0
 private void LogEvent(string methodInfo, LogEventInfo logEvent)
 {
     if (!string.IsNullOrEmpty(methodInfo))
     {
         logEvent.SetCallerInfo(_typeFullName, methodInfo, string.Empty, 0);
     }
     _logger.Log(typeof(LoggerAdapter), logEvent);
 }