Esempio n. 1
0
 public static void SetStatusCode(this IKLogger logger, int statusCode)
 {
     if (logger != null && logger is Logger _logger)
     {
         _logger.DataContainer.LoggerProperties.ExplicitStatusCode = statusCode;
     }
 }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Logger.SetFactory(new LoggerFactory(new Logger(url: "ConsoleApp/Main")));

            ConfigureKissLog();

            IKLogger logger = Logger.Factory.Get();

            logger.Trace("Trace log");
            logger.Debug("Debug log");
            logger.Info("Information log");
            logger.Warn("Warning log");
            logger.Error("Error log");
            logger.Critical("Critical log");

            logger.Error(new DivideByZeroException());

            string file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App.config");

            logger.LogAsFile($"Text content logged as file. Guid: {Guid.NewGuid()}", "file-01.txt");
            logger.LogFile(file, "App.config");

            logger.AddCustomProperty("CorrelationId", Guid.NewGuid());
            logger.AddCustomProperty("boolean", true);
            logger.AddCustomProperty("date", DateTime.UtcNow);
            logger.AddCustomProperty("integer", 100);

            var loggers = Logger.Factory.GetAll();

            Logger.NotifyListeners(loggers);
        }
Esempio n. 3
0
 public static void LogResponseBody(this IKLogger logger, bool value)
 {
     if (logger != null && logger is Logger _logger)
     {
         _logger.DataContainer.LoggerProperties.ExplicitLogResponseBody = value;
     }
 }
Esempio n. 4
0
 public static void AddCustomProperty(this IKLogger logger, string name, string value)
 {
     if (logger != null && logger is Logger _logger)
     {
         Add(_logger, name, value);
     }
 }
 public static void LogAsFile(this IKLogger logger, string contents, string fileName = null)
 {
     if (logger != null && logger is Logger _logger)
     {
         _logger.DataContainer.FilesContainer.LogAsFile(contents, fileName);
     }
 }
 public static void LogFile(this IKLogger logger, string sourceFilePath, string fileName = null)
 {
     if (logger != null && logger is Logger _logger)
     {
         _logger.DataContainer.FilesContainer.LogFile(sourceFilePath, fileName);
     }
 }
Esempio n. 7
0
        public static bool AutoFlush(this IKLogger logger)
        {
            if (logger != null && logger is Logger _logger)
            {
                return(_logger.DataContainer.LoggerProperties.IsManagedByHttpRequest == true);
            }

            return(false);
        }
Esempio n. 8
0
        /// <summary>
        /// Writes a Log message
        /// </summary>
        /// <param name="message">Log data</param>
        public static void Debug(this IKLogger logger, string message,
                                 [System.Runtime.CompilerServices.CallerMemberName] string memberName = null,
                                 [System.Runtime.CompilerServices.CallerLineNumber] int lineNumber    = 0,
                                 [System.Runtime.CompilerServices.CallerFilePath] string memberType   = null)
        {
            if (logger == null)
            {
                return;
            }

            logger.Log(LogLevel.Debug, message, memberName, lineNumber, memberType);
        }
Esempio n. 9
0
        /// <summary>
        /// Writes a Log message
        /// </summary>
        /// <param name="args">
        ///     <para>A collection of Log data</para>
        ///     <para>Eg: new KissLog.Args("value1", 100)</para>
        /// </param>
        public static void Trace(this IKLogger logger, Args args, JsonSerializeOptions options        = null,
                                 [System.Runtime.CompilerServices.CallerMemberName] string memberName = null,
                                 [System.Runtime.CompilerServices.CallerLineNumber] int lineNumber    = 0,
                                 [System.Runtime.CompilerServices.CallerFilePath] string memberType   = null)
        {
            if (logger == null)
            {
                return;
            }

            logger.Log(LogLevel.Trace, args, options, memberName, lineNumber, memberType);
        }
Esempio n. 10
0
        /// <summary>
        /// Writes a Log message
        /// </summary>
        /// <param name="ex">Log data</param>
        public static void Trace(this IKLogger logger, Exception ex,
                                 [System.Runtime.CompilerServices.CallerMemberName] string memberName = null,
                                 [System.Runtime.CompilerServices.CallerLineNumber] int lineNumber    = 0,
                                 [System.Runtime.CompilerServices.CallerFilePath] string memberType   = null)
        {
            if (logger == null)
            {
                return;
            }

            logger.Log(LogLevel.Trace, ex, memberName, lineNumber, memberType);
        }
Esempio n. 11
0
        /// <summary>
        /// Writes a Log message
        /// </summary>
        /// <param name="json">Log data</param>
        public static void Critical(this IKLogger logger, object json, JsonSerializeOptions options      = null,
                                    [System.Runtime.CompilerServices.CallerMemberName] string memberName = null,
                                    [System.Runtime.CompilerServices.CallerLineNumber] int lineNumber    = 0,
                                    [System.Runtime.CompilerServices.CallerFilePath] string memberType   = null)
        {
            if (logger == null)
            {
                return;
            }

            logger.Log(LogLevel.Critical, json, options, memberName, lineNumber, memberType);
        }
Esempio n. 12
0
        protected override void Write(LogEventInfo logEvent)
        {
            if (logEvent == null)
            {
                return;
            }

            LogLevel logLevel = GetLogLevel(logEvent.Level.Name);
            string   message  = Layout.Render(logEvent);

            IKLogger logger = Logger.Factory.Get();

            if (!string.IsNullOrEmpty(logEvent.CallerClassName))
            {
                logger.Log(logLevel, message, logEvent.CallerMemberName, logEvent.CallerLineNumber, logEvent.CallerClassName);
            }
            else
            {
                logger.Log(logLevel, message, string.Empty, 0, string.Empty);
            }
        }
Esempio n. 13
0
        protected override void Append(LoggingEvent loggingEvent)
        {
            if (loggingEvent == null)
            {
                return;
            }

            LogLevel logLevel = GetLogLevel(loggingEvent.Level.Name);
            string   message  = RenderLoggingEvent(loggingEvent);

            IKLogger logger = Logger.Factory.Get();

            if (!string.IsNullOrEmpty(loggingEvent.LocationInformation?.ClassName))
            {
                int lineNumber = 0;
                int.TryParse(loggingEvent.LocationInformation?.LineNumber, out lineNumber);

                logger.Log(logLevel, message, loggingEvent.LocationInformation.MethodName, lineNumber, loggingEvent.LocationInformation.ClassName);
            }
            else
            {
                logger.Log(logLevel, message, string.Empty, 0, string.Empty);
            }
        }
Esempio n. 14
0
 public HomeController()
 {
     _logger = Logger.Factory.Get();
 }
Esempio n. 15
0
 public ValuesController()
 {
     _logger = Logger.Factory.Get();
 }