Beispiel #1
0
        public IActionResult Index()
        {
            //ILogger
            _logger.BeginScope("User: {username}", User.Identity?.Name);
            _logger.LogInformation("Hey! I'm in the Index!");
            try
            {
                for (int i = 0; i < 10; i++)
                {
                    _logger.LogInformation("For loop... {i}", i);
                    if (i == 5)
                    {
                        throw new Exception("ups!");
                    }
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Strange... something broke");
            }

            //Serilog

            _myLogger.ForContext("User", User.Identity?.Name);
            _myLogger.Information("User: {username}", User.Identity?.Name);

            try
            {
                for (int i = 0; i < 10; i++)
                {
                    _myLogger.Information("For loop... {i}", i);

                    if (i == 5)
                    {
                        throw new Exception("ups!");
                    }
                }
            }
            catch (Exception e)
            {
                _myLogger.Error(e, "Strange... something broke");
            }

            return(View());
        }
Beispiel #2
0
 public ILog GetLogger(Type type)
 {
     return(new Log(_logger.ForContext(type).Information, _logger.ForContext(type).Debug, _logger.ForContext(type).Error));
 }
 public SerilogTests(SerilogConfiguration configuration = null)
 {
     factory = LoggerBuilders.BuildSerilogLogFactory(configuration);
     logger  = factory.ForContext <IAuditLogger>();
 }