public IActionResult Privacy() { try { Customer customer = new Customer() { FirstName = "Isaac", LastName = "Obote", Age = new Age() { DOB = DateTime.Today }, Contact = new Contact() { Email = "*****@*****.**", Phone = new List <string>() { "256(772)1234756", "256(780)1209399" } } }; _auditor.AuditEvent("Privacy", null, ActionType.Update, HttpContext.User.Identity.Name, "Updated Customer", customer); _logger.LogInformation("Privacy", null, ActionType.Update, $"Updated Customer {customer.FirstName}", null); Payment pay = new Payment() { Amount = new Random().Next(10000, 50000) }; _auditor.AuditEvent <Payment>("Privacy", null, ActionType.Create, HttpContext.User.Identity.Name, $"Created Transaction {pay.Amount}", pay); _logger.LogInformation("Privacy", null, ActionType.Create, "Created Transaction Succefully", null); } catch (System.Exception ex) { _logger.LogError("Privacy", "", ActionType.Execute, nameof(ActionType.View), ex); } 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}"); } }