public CoreLogger(IOptions <CoreLoggerConfiguration> configuration) { _configuration = configuration.Value ?? throw new ArgumentNullException("Configurations cannot be null"); if (!string.IsNullOrWhiteSpace(_configuration.SQL_ConnectionString)) { using (var ctx = new ContextSQL(_configuration.SQL_ConnectionString)) { ctx.Database.Migrate(); } } }
private Task <IEnumerable <Log_Master> > SQL_ListAsync(int?level = null, DateTime?from = null, DateTime?to = null) { IEnumerable <Log_Master> entities = null; if (_configuration.UseSQL) { using (var ctx = new ContextSQL(_configuration.SQL_ConnectionString)) entities = ctx.Logger_Masters .Where(t => level.HasValue ? level.Value == t.LevelID : true) .Where(t => from.HasValue ? from.Value.Date <= t.DateTime : true) .Where(t => to.HasValue ? to.Value.AddDays(1).Date > t.DateTime : true) .ToList(); } return(Task.FromResult(entities)); }
public Task LogInformation(string message, string data = null, [CallerMemberName] string caller = "", [CallerLineNumber] int line = 0) { var entity = new Log_Master() { DateTime = DateTime.Now, LevelID = (int)LogLevel.Information, CallerMemberName = caller, CallerMemberLineNumber = line, Message = message, FullData = data }; if (_configuration.UseDailyLogFile) { using (var ctx = new ContextFile(_configuration.File_FolderPath)) ctx.Log(entity); } if (_configuration.UseSQLite) { using (var ctx = new ContextSQLite(_configuration.SQLite_FullPath)) { ctx.Logger_Masters.Add(entity); ctx.SaveEntitiesAsync(); } } if (_configuration.UseSQL) { using (var ctx = new ContextSQL(_configuration.SQL_ConnectionString)) { entity.ID = 0; ctx.Logger_Masters.Add(entity); ctx.SaveEntitiesAsync(); } } return(Task.CompletedTask); }