public IActionResult Index() { if (HttpContext.User.Identity.IsAuthenticated) { _auditor.AuditEvent("Index", null, ActionType.View, HttpContext.User.Identity.Name, "View Page", null); } _logger.LogInformation("Index", null, ActionType.View, "View Page", null); return(View()); }
static void Main(string[] args) { var context = new LoggerContextFactory().CreateDbContext(null); EasyLogger logger = new EasyLogger( new ApenLoggerConfiguration() { LogRepository = LogRepository.Database, FileLogOption = new FileLogOption() { LogFileInterval = LogFileInterval.Hourly, FilePath = @".\Logs\" } }, context ); EasyAuditor auditor = new EasyAuditor( new ApenLoggerConfiguration() { LogRepository = LogRepository.Database, FileLogOption = new FileLogOption() { LogFileInterval = LogFileInterval.Hourly, FilePath = @".\Logs\" } }, context ); logger.LogInformation("", "", ActionType.Approve, "StartUp", null); for (int i = 0; i < 99; i++) { var d = i <= 30 ? (i + 1) : (i % 30 == 0 ? 1 : (i % 30)); var x = new WeatherForecastWithPOCOs() { Date = DateTime.Now.AddDays(i), TemperatureCelsius = i, Summary = $"Hot", DatesAvailable = new List <DateTimeOffset>() { DateTime.Parse($"2019-08-{d:00}T00:00:00-07:00"), DateTime.Parse($"2019-08-{d:00}T00:00:00-07:00") }, SummaryWords = new List <string> { "Cool", "Windy", "Humid" }.ToArray() }; logger.LogInformation(nameof(Program), i.ToString(), ActionType.Execute, "StartUp", x); if (i % 2 == 0) { logger.LogInformation(nameof(Program), i.ToString(), ActionType.Create, $"Looping Values ({i})", x); auditor.AuditEvent(nameof(Program), i.ToString(), ActionType.Create, "*****@*****.**", "Create", x); } if (i % 3 == 0) { logger.LogCritical(nameof(Program), i.ToString(), ActionType.Update, $"Looping Values ({i})", x); auditor.AuditEvent(nameof(Program), i.ToString(), ActionType.Update, "*****@*****.**", "Updated", x); } if (i % 5 == 0) { logger.LogError(nameof(Program), i.ToString(), ActionType.Approve, $"Looping Values ({i})", x); auditor.AuditEvent(nameof(Program), i.ToString(), ActionType.Approve, "*****@*****.**", "Approve", x); } if (i % 7 == 0) { logger.LogWarning(nameof(Program), i.ToString(), ActionType.Delete, $"Looping Values ({i})", x); auditor.AuditEvent(nameof(Program), i.ToString(), ActionType.Delete, "*****@*****.**", "Deleted", x); } } var logs = context.SystemLogs.ToList(); foreach (var item in logs) { Console.WriteLine($"{item.Id} | {item.Executed} | {item.LogLevel} | {item.Source} | {item.ActionType} | {item.Action} | {item.Reference} | {item.Detail}"); } var audittrail = context.AuditLogs.ToList(); foreach (var item in audittrail) { Console.WriteLine($"{item.Id} | {item.Executed} | {item.Actor} | {item.Source} | {item.ActionType} | {item.Action} | {item.Reference} | {item.Detail}"); } }