public ApplicationLogMessage(IConfigurationSetting configurationSetting, string requestId, string internalRequestId, string message, LogEventLevel logEventLevel, Exception exception) { _configurationSetting = configurationSetting; RequestId = requestId; InternalRequestId = internalRequestId; Message = message; LogEventLevel = logEventLevel.ToString(); Exception = exception?.ToString(); }
private void WriteAttributes(IConfigurationSetting s) { if (!string.IsNullOrEmpty(s.Category)) { _writer.WriteLine(Invariant($"# [{ConfigurationSettingAttributeNames.Category}] {s.Category}")); } if (!string.IsNullOrEmpty(s.Description)) { _writer.WriteLine(Invariant($"# [{ConfigurationSettingAttributeNames.Description}] {s.Description}")); } if (!string.IsNullOrEmpty(s.EditorType)) { _writer.WriteLine(Invariant($"# [{ConfigurationSettingAttributeNames.Editor}] {s.EditorType}")); } }
private static string FormatValue(IConfigurationSetting s) { if (s.ValueType == ConfigurationSettingValueType.String) { var hasSingleQuotes = s.Value.IndexOf('\'') >= 0; var hasDoubleQuotes = s.Value.IndexOf('\"') >= 0; if (hasSingleQuotes && !hasDoubleQuotes) { return s.Value.ToRStringLiteral(quote: '"'); } else { return s.Value.ToRStringLiteral(quote: '\''); } } return s.Value; }
private static IEnumerable <IConfigurationSetting> ExtractSettingsObjects(IConfigurationSetting settingsObject) { var properties = settingsObject.GetType().GetProperties(); foreach (var property in properties) { var value = property.GetValue(settingsObject) as IConfigurationSetting; if (value != null) { yield return(value); } } }
public async Task Invoke(HttpContext context, ILogger logger, IConfigurationSetting setting) { try { await _next(context); } catch (Exception ex) { await logger.Error(new ApplicationLogMessage(setting, context.Request.GetRequestId1()?.ToString(), context.Request.GetInternalRequestId1(), string.Empty, LogEventLevel.Error, ex)); await HandleExceptionAsync(context, ex); } }
private static string FormatValue(IConfigurationSetting s) { if (s.ValueType == ConfigurationSettingValueType.String) { var hasSingleQuotes = s.Value.IndexOf('\'') >= 0; var hasDoubleQuotes = s.Value.IndexOf('\"') >= 0; if (hasSingleQuotes && !hasDoubleQuotes) { return(Invariant($"\"{s.Value}\"")); } else if (!hasSingleQuotes) { return(Invariant($"'{s.Value}'")); } } return(s.Value); }
private static string FormatValue(IConfigurationSetting s) { if (s.ValueType == ConfigurationSettingValueType.String) { var hasSingleQuotes = s.Value.IndexOf('\'') >= 0; var hasDoubleQuotes = s.Value.IndexOf('\"') >= 0; if (hasSingleQuotes && !hasDoubleQuotes) { return(s.Value.ToRStringLiteral(quote: '"')); } else { return(s.Value.ToRStringLiteral(quote: '\'')); } } return(s.Value); }
public HttpRequestResponseLogMessage(IConfigurationSetting configurationSetting, HttpRequest request, HttpResponse response, Stopwatch stopwatch, string requestContent, string responseContent) { _configurationSetting = configurationSetting; var requestDetails = BuildRequestDetails(request, requestContent); var responseDetails = BuildResponseDetails(response, request, stopwatch, responseContent); RequestId = requestDetails.RequestId; InternalRequestId = requestDetails.InternalRequestId; Request = requestDetails; UserId = requestDetails.UserId; ClientId = requestDetails.ClientId; RequestUri = requestDetails.RequestUri; ClientIpAddress = requestDetails.ClientIpAddress; ProcessingTime = responseDetails.TotalMilliseconds; Response = responseDetails; Endpoint = request?.GetEndpoint(); }
/// <inheritdoc/> public void Update(IConfigurationSetting config, bool clearCache) { try { var dbProvider = DataProvider.Instance(); var userId = UserController.Instance.GetCurrentUserInfo().UserID; var portalSettings = PortalController.Instance.GetCurrentPortalSettings(); var settings = GetSettingsFromDatabase(); if (settings.ContainsKey(config.Key)) { IConfigurationSetting currentconfig; settings.TryGetValue(config.Key, out currentconfig); if (currentconfig != null && currentconfig.Value != config.Value) { dbProvider.UpdateHostSetting(config.Key, config.Value, config.IsSecure, userId); EventLogController.Instance.AddLog( config.Key, config.Value, portalSettings, userId, EventLogController.EventLogType.HOST_SETTING_UPDATED); } } else { dbProvider.UpdateHostSetting(config.Key, config.Value, config.IsSecure, userId); EventLogController.Instance.AddLog( config.Key, config.Value, portalSettings, userId, EventLogController.EventLogType.HOST_SETTING_CREATED); } } catch (Exception ex) { Exceptions.LogException(ex); } if (clearCache) { DataCache.RemoveCache(DataCache.HostSettingsCacheKey); } }
public SettingPropertyDescriptor(ICoreShell coreShell, IConfigurationSetting setting) : base(setting.Name, null) { _coreShell = coreShell; Setting = setting; }
public MessageLoggingMiddleware(IConfigurationSetting configurationSetting, ILogger logger, RequestDelegate next) { _configurationSetting = configurationSetting; _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _next = next ?? throw new ArgumentNullException(nameof(next)); }
public DbConnectionFactory(IConfigurationSetting configuration, ILogger <DbConnectionFactory> logger) { _configuration = configuration; _logger = logger; }
/// <inheritdoc/> public void Update(IConfigurationSetting config) { this.Update(config, true); }
public void RemoveSetting(IConfigurationSetting s) { _settings.Remove(s); }
public async Task InvokeAsync(HttpContext context, IConfigurationSetting setting) { try { // if the request id doesn't exist, it is not coming from the API, we can ignore that. if (!context.Request.Headers.ContainsKey(RequestIdKey) && context.Request.GetRequestUri().ToString().Contains("heartbeat")) { await _next(context); return; } var request = context.Request; if (!request.Headers.ContainsKey(HttpHeaders.InternalRequestIdHeader)) { request.Headers.Add(HttpHeaders.InternalRequestIdHeader, Guid.NewGuid().ToString()); request.Headers.Add(ReferenceEndpointKey, request.GetUri().ToString()); } var stopwatch = Stopwatch.StartNew(); // needs to capture the content before passing to the pipeline since the stream will be at the end // when the processing finish var requestContent = string.Empty; if (!string.Equals(request.Method, WebRequestMethods.Http.Get, StringComparison.OrdinalIgnoreCase)) { requestContent = await FormatRequest(request); } var originalBodyStream = context.Response.Body; var needToCaptureResponse = string.Empty; var needToCapture = !string.Equals(request.Method, WebRequestMethods.Http.Get, StringComparison.OrdinalIgnoreCase); if (needToCapture) { using (var responseBody = new MemoryStream()) { context.Response.Body = responseBody; try { await _next(context); stopwatch.Stop(); needToCaptureResponse = await FormatResponse(context.Response); await responseBody.CopyToAsync(originalBodyStream); } finally { // to make sure the caller of this middleware can still manipulate the // content in the response stream context.Response.Body = originalBodyStream; } } } else { await _next(context); stopwatch.Stop(); } await LogDetails(request, context.Response, stopwatch, requestContent, needToCaptureResponse); } catch (Exception ex) { await _logger.Error(new ApplicationLogMessage(setting, context.Request.GetRequestId1()?.ToString(), context.Request.GetInternalRequestId1(), "Error occured while trying to perform logging.", LogEventLevel.Error, ex)); } }
protected void Application_Start() { Container container = new Container(); IoC.Configure(container); //RouteTable.Routes.MapHubs(); //assign instrumentation key to appinsights Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.InstrumentationKey = System.Web.Configuration.WebConfigurationManager.AppSettings["iKey"]; ControllerBuilder.Current.SetControllerFactory(typeof(SmarttouchControllerFactory)); AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); //ControllerBuilder.Current.SetControllerFactory(typeof(SmarttouchControllerFactory)); InitializeAutoMapper.Initialize(); //GlobalConfiguration.Configuration.EnsureInitialized(); HttpContext.Current.Application["image_hostedpath"] = ConfigurationManager.AppSettings["IMAGE_HOSTING_SERVICE_URL"]; HttpContext.Current.Application["webservice_url"] = ConfigurationManager.AppSettings["WEBSERVICE_URL"]; Logger.Current.CreateRollingFlatFileListener(EventLevel.Verbose, ConfigurationManager.AppSettings["WEBAPP_LOG_FILE_PATH"], 2048); ExceptionHandler.Current.AddDefaultLogAndRethrowPolicy(); ExceptionHandler.Current.AddDefaultLogOnlyPolicy(); i18n.LocalizedApplication.Current.DefaultLanguage = "en"; i18n.UrlLocalizer.UrlLocalizationScheme = i18n.UrlLocalizationScheme.Void; var defaultJsonFactory = ValueProviderFactories.Factories.OfType <JsonValueProviderFactory>().FirstOrDefault(); var index = ValueProviderFactories.Factories.IndexOf(defaultJsonFactory); ValueProviderFactories.Factories.Remove(defaultJsonFactory); ValueProviderFactories.Factories.Insert(index, new SmartTouchJsonValueProviderFactory()); bool isHttpsMode = false; string httpsMode = System.Configuration.ConfigurationManager.AppSettings["IsHttpsMode"]; bool.TryParse(httpsMode, out isHttpsMode); ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new RazorViewEngine()); var masterAccountDns = ConfigurationManager.AppSettings["MASTER_ACCOUNT_DNS"]; if (masterAccountDns.Equals("localhost")) { using (var socketServerContainer = Composable.GetExport <IXSocketServerContainer>()) { socketServerContainer.StartServers(); } } else { using (var socketServerContainer = Composable.GetExport <IXSocketServerContainer>()) { IList <IConfigurationSetting> configurationSettings = new List <IConfigurationSetting>(); //string uri = string.Empty; IConfigurationSetting configSetting = null; Uri uri = null; if (isHttpsMode) { string sslKey = System.Configuration.ConfigurationManager.AppSettings["SSLSerialNumber"]; uri = new Uri("wss://" + ConfigurationManager.AppSettings["MASTER_ACCOUNT_DNS"] + ":" + ConfigurationManager.AppSettings["WEBSOCKET_PORT"]); X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine); store.Open(OpenFlags.ReadOnly); var certificate = store.Certificates.Find(X509FindType.FindBySerialNumber, sslKey, false).OfType <X509Certificate2>().FirstOrDefault(); if (certificate != null) { Logger.Current.Informational("certificate found"); configSetting = new ConfigurationSetting { Port = uri.Port, Origin = new HashSet <string>() { "*" }, Uri = uri, Certificate = certificate }; Logger.Current.Informational("Configured was mode for websockets."); } else { Logger.Current.Informational("certificate not found"); foreach (X509Certificate2 objCert in store.Certificates) { string serialNumber = objCert.SerialNumber.Trim().ToString().ToUpper(); Logger.Current.Verbose("Certificate name" + objCert.FriendlyName + " Store serial number:" + objCert.SerialNumber.Trim()); string orgSerialNumber = sslKey.Trim().ToString().ToUpper(); if (String.Equals(serialNumber, orgSerialNumber, StringComparison.InvariantCulture)) { certificate = objCert; } } if (certificate != null) { Logger.Current.Informational("Certificate found."); configSetting = new ConfigurationSetting { Port = uri.Port, Origin = new HashSet <string>() { "*" }, Uri = uri, Certificate = certificate }; Logger.Current.Informational("Configured wss mode for websockets."); } else { Logger.Current.Informational("Certificate not found. Could not set wss for the application."); } } } else { uri = new Uri("ws://" + ConfigurationManager.AppSettings["MASTER_ACCOUNT_DNS"] + ":" + ConfigurationManager.AppSettings["WEBSOCKET_PORT"]); configSetting = new ConfigurationSetting(uri); Logger.Current.Informational("Configured ws mode for websockets."); } configurationSettings.Add(configSetting); socketServerContainer.StartServers(withInterceptors: true, configurationSettings: configurationSettings); } } }
public ApplicationLogMessage(IConfigurationSetting configurationSetting, string requestId, string internalRequestId, string message, LogEventLevel logEventLevel) : this(configurationSetting, requestId, internalRequestId, message, logEventLevel, (Exception)null) { }