public void UpdateConnectionString(string connectionString) { connectionString = DenormalizeConnectionString(connectionString); if (_config.GetConnectionString(SettingKeys.ConnectionStringKey) != connectionString) { _configManager.AddOrUpdateSetting($"{SettingKeys.ConnectionStringsSection}:{SettingKeys.ConnectionStringKey}", connectionString, true); } }
private void Upgrade_2_1_0(Tenant tenant, IServiceScope scope) { if (tenant.Name == TenantNames.Master) { _configManager.RemoveSetting("Localization:SupportedCultures", true); if (_configManager.GetSetting("RenderMode", "") == "") { _configManager.AddOrUpdateSetting("RenderMode", "ServerPrerendered", true); } } }
public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { if (_configManager.GetSetting("Logging:FileLogger:LogLevel:Default", "") == "") { _configManager.AddOrUpdateSetting("Logging:FileLogger:LogLevel:Default", "Error", true); if (logLevel < LogLevel.Error) { return; } } if (!IsEnabled(logLevel)) { return; } string folder = Path.Combine(_environment.ContentRootPath, "Content", "Log"); var filepath = Path.Combine(folder, "error.log"); long size = 0; // ensure directory exists if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } if (File.Exists(filepath)) { var fileinfo = new FileInfo(filepath); size = fileinfo.Length; // only retain an error log for the current day as it is intended for development purposes if (fileinfo.LastWriteTimeUtc.Date < DateTime.UtcNow.Date) { File.Delete(filepath); } } // do not allow the log to exceed 1 MB if (size < 1000000) { try { var logentry = string.Format("{0} [{1}] {2} {3}", "[" + DateTimeOffset.UtcNow.ToString("yyyy-MM-dd HH:mm:ss+00:00") + "]", logLevel.ToString(), formatter(state, exception), exception != null ? exception.StackTrace : ""); using (var streamWriter = new StreamWriter(filepath, true)) { streamWriter.WriteLine(logentry); } } catch { // error occurred } } }
public void Post([FromBody] Dictionary <string, string> settings) { foreach (KeyValuePair <string, string> kvp in settings) { switch (kvp.Key) { case "runtime": _configManager.AddOrUpdateSetting("Runtime", kvp.Value, false); break; case "rendermode": _configManager.AddOrUpdateSetting("RenderMode", kvp.Value, false); break; case "detailederrors": _configManager.AddOrUpdateSetting("DetailedErrors", kvp.Value, false); break; case "logginglevel": _configManager.AddOrUpdateSetting("Logging:LogLevel:Default", kvp.Value, false); break; case "swagger": _configManager.AddOrUpdateSetting("UseSwagger", kvp.Value, false); break; case "packageservice": _configManager.AddOrUpdateSetting("PackageService", kvp.Value, false); break; } } }
public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { if (_configManager.GetSetting("Logging:FileLogger:LogLevel:Default", "") == "") { _configManager.AddOrUpdateSetting("Logging:FileLogger:LogLevel:Default", "Error", true); if (logLevel < LogLevel.Error) { return; } } if (!IsEnabled(logLevel)) { return; } string folder = Path.Combine(_environment.ContentRootPath, "Content", "Log"); // ensure directory exists if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } var filepath = Path.Combine(folder, "error.log"); var logentry = string.Format("{0} [{1}] {2} {3}", "[" + DateTimeOffset.UtcNow.ToString("yyyy-MM-dd HH:mm:ss+00:00") + "]", logLevel.ToString(), formatter(state, exception), exception != null ? exception.StackTrace : ""); try { using (var streamWriter = new StreamWriter(filepath, true)) { streamWriter.WriteLine(logentry); } } catch { // error occurred } }