public virtual void SendMessageToAll <T>(string messageKey, T?messageArgs) where T : class { if (messageKey == null) { throw new ArgumentNullException(nameof(messageKey)); } IHubContext hubContext = _connectionManager.GetHubContext <MessagesHub>(); string objectArgsAsString = messageArgs == null ? string.Empty : ContentFormatter.Serialize(messageArgs); hubContext.Clients.All.OnMessageReceived(messageKey, objectArgsAsString); }
public virtual void SaveLog(LogEntry logEntry) { if (logEntry == null) { throw new ArgumentNullException(nameof(logEntry)); } EventLog appLog = new EventLog("Application") { Source = _activeAppEnvironment.AppInfo.Name }; EventLogEntryType eventLogsSeverity; if (logEntry.Severity == "Warning") { eventLogsSeverity = EventLogEntryType.Warning; } else if (logEntry.Severity == "Information") { eventLogsSeverity = EventLogEntryType.Information; } else { eventLogsSeverity = EventLogEntryType.Error; } string logContents = ContentFormatter.Serialize(logEntry); if (logContents.Length >= 30000) { logContents = logContents.Substring(0, 29999); } if (_activeAppEnvironment.TryGetConfig("EventLogId", out long eventLogId)) { appLog.WriteEntry(logContents, eventLogsSeverity, Convert.ToInt32(eventLogId)); } else { appLog.WriteEntry(logContents, eventLogsSeverity); } }
public virtual async Task <SSOPageModel> GetSSOPageModelAsync(CancellationToken cancellationToken) { return(new SSOPageModel { AppTitle = _activeAppEnvironment .Cultures .ExtendedSingle($"Finding cultures of {_activeAppEnvironment.AppInfo.DefaultCulture} in {_activeAppEnvironment.Name} environment", c => c.Name == _activeAppEnvironment.AppInfo.DefaultCulture) .Values .ExtendedSingle($"Finding AppTitle in {_activeAppEnvironment.AppInfo.DefaultCulture} cultures of {_activeAppEnvironment.Name} environment", v => v.Name == "AppTitle").Title, AppName = _activeAppEnvironment.AppInfo.Name, AppVersion = _activeAppEnvironment.AppInfo.Version, Culture = _activeAppEnvironment.AppInfo.DefaultCulture, DebugMode = _activeAppEnvironment.DebugMode, DesiredTimeZoneValue = _activeAppEnvironment.AppInfo.DefaultTimeZone, Theme = _activeAppEnvironment.AppInfo.DefaultTheme, EnvironmentConfigsJson = ContentFormatter.Serialize(_activeAppEnvironment .Configs.Where(c => c.AccessibleInClientSide == true) .Select(c => new { value = c.Value, key = c.Key })), BaseHref = _activeAppEnvironment.GetHostVirtualPath() }); }
public virtual void SendMessageToUsers <T>(string messageKey, T?messageArgs, string[] userIds) where T : class { if (userIds == null) { throw new ArgumentNullException(nameof(userIds)); } if (messageKey == null) { throw new ArgumentNullException(nameof(messageKey)); } IHubContext hubContext = _connectionManager.GetHubContext <MessagesHub>(); string objectArgsAsString = messageArgs == null ? string.Empty : ContentFormatter.Serialize(messageArgs); foreach (string u in userIds) { hubContext.Clients.Group(u).OnMessageReceived(messageKey, objectArgsAsString); } }
List <AppInsightsLogKeyVal> PopulateLogKeyValues(LogEntry logEntry) { List <AppInsightsLogKeyVal?> keyValues = logEntry.LogData.Select(ld => { string k = ld.Key; if (k == nameof(IRequestInformationProvider.HttpMethod) || k == nameof(IRequestInformationProvider.DisplayUrl) || k == "ResponseStatusCode" || k == nameof(IRequestInformationProvider.ClientIp) || ld.Value == null) { return(null); // Already being logged by app insights! } string?v = null; if (ld.Value is string valueAsStr) { v = valueAsStr; } if (k == "ClientLogs" || k == "OperationArgs") { v = ContentFormatter.Serialize(ld.Value); } else { v = ld.Value.ToString(); } return(new AppInsightsLogKeyVal { Key = k, Value = v }); }) .Where(d => d != null) .ToList(); keyValues.Add(new AppInsightsLogKeyVal { Key = nameof(LogEntry.MemoryUsage), Value = logEntry.MemoryUsage.ToString(CultureInfo.InvariantCulture) }); if (logEntry.AppServerDateTime != null) { keyValues.Add(new AppInsightsLogKeyVal { Key = nameof(LogEntry.AppServerDateTime), Value = logEntry.AppServerDateTime.ToString() }); } keyValues.Add(new AppInsightsLogKeyVal { Key = nameof(LogEntry.Severity), Value = logEntry.Severity }); keyValues.Add(new AppInsightsLogKeyVal { Key = nameof(LogEntry.Message), Value = logEntry.Message }); if (logEntry.Id != null) { keyValues.Add(new AppInsightsLogKeyVal { Key = nameof(LogEntry.Id), Value = logEntry.Id.ToString() }); } if (logEntry.AppServerThreadId != null) { keyValues.Add(new AppInsightsLogKeyVal { Key = nameof(LogEntry.AppServerThreadId), Value = logEntry.AppServerThreadId.ToString() }); } return(keyValues !); }