public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { Log log = new(); log.LogLevel = logLevel.ToString(); log.ExceptionMessage = exception?.Message; log.StackTrace = exception?.StackTrace; log.Source = "Server"; log.CreatedDate = DateTime.Now.ToString(); _context.Logs.Add(log); _context.SaveChanges(); }
public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { var userId = _httpContextAccessor?.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; Log log = new(); log.LogLevel = logLevel.ToString(); log.UserId = Convert.ToInt64(userId); log.ExceptionMessage = exception?.Message; log.StackTrace = exception?.StackTrace; log.Source = "Server"; log.CreatedDate = DateTime.Now.ToString(); _context.Logs.Add(log); _context.SaveChanges(); }
public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { //Need to figure out how can we get userid for the logger when using JWT authorization long userId = 0; Log log = new(); log.LogLevel = logLevel.ToString(); log.UserId = Convert.ToInt64(userId); log.ExceptionMessage = exception?.Message; log.StackTrace = exception?.StackTrace; log.Source = "Server"; log.CreatedDate = DateTime.Now.ToString(); _context.Logs.Add(log); _context.SaveChanges(); }