public void Log <TState> (LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { if (IsEnabled(logLevel)) { ActionLog log = null; if (typeof(TState) != typeof(ActionLog)) { ActionLogTypesEnum ll = ActionLogTypesEnum.Normal; if (logLevel == LogLevel.Trace || logLevel == LogLevel.Debug) { ll = ActionLogTypesEnum.Debug; } if (logLevel == LogLevel.Error || logLevel == LogLevel.Warning || logLevel == LogLevel.Critical) { ll = ActionLogTypesEnum.Exception; } log = new ActionLog { Remark = formatter?.Invoke(state, exception), CreateTime = DateTime.Now, ActionTime = DateTime.Now, ActionName = "System Log", ModuleName = "System Log", LogType = ll }; } else { log = state as ActionLog; } if (cs != null) { using var dc = cs.CreateDC(); if (dc != null) { dc.AddEntity <ActionLog>(log); dc.SaveChanges(); } } } }