コード例 #1
0
ファイル: Program.cs プロジェクト: KissLog-net/KissLog.Sdk
        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);
        }
コード例 #2
0
        public ActionResult Index()
        {
            _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, "Web.config");

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

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

            _logger.LogResponseBody(true);

            Logger       logger = _logger as Logger;
            FlushLogArgs args   = FlushLogArgsFactory.Create(new[] { logger });
            string       json   = JsonSerializer.Serialize(args, new JsonSerializerOptions {
                WriteIndented = true
            });

            return(Content(json, "application/json"));
        }