public static void SafeAppendColumn(RequestDetailsLoggerBase <T> requestDetailsLogger, Enum columnName, string key, string value) { RequestDetailsLoggerBase <T> .SafeLogOperation <string, string>(requestDetailsLogger, key, value, delegate(RequestDetailsLoggerBase <T> logger, string k, string v) { logger.SafeAppend(columnName, key, value); }); }
public static void SafeAppendGenericInfo(RequestDetailsLoggerBase <T> requestDetailsLogger, string key, object value) { if (value != null && RequestDetailsLoggerBase <T> .RequestLoggerConfig != null) { RequestDetailsLoggerBase <T> .SafeAppendColumn(requestDetailsLogger, RequestDetailsLoggerBase <T> .RequestLoggerConfig.GenericInfoColumn, key, value.ToString()); } }
public static void SafeSetLogger(RequestDetailsLoggerBase <T> requestDetailsLogger, Enum key, object value) { RequestDetailsLoggerBase <T> .SafeLogOperation <Enum, object>(requestDetailsLogger, key, value, delegate(RequestDetailsLoggerBase <T> logger, Enum k, object v) { logger.Set(k, v); }); }
public static void SafeLogRequestException(RequestDetailsLoggerBase <T> requestDetailsLogger, Exception ex, string keyPrefix) { RequestDetailsLoggerBase <T> .SafeLogOperation <Exception, string>(requestDetailsLogger, ex, keyPrefix, delegate(RequestDetailsLoggerBase <T> logger, Exception k, string v) { logger.LogExceptionToGenericError(k, v); }); }
private static void GlobalActivityLogger(object sender, ActivityEventArgs args) { IActivityScope activityScope = sender as IActivityScope; if (activityScope.ActivityType == ActivityType.Global && (args.ActivityEventType == ActivityEventType.EndActivity || args.ActivityEventType == ActivityEventType.SuspendActivity)) { RequestDetailsLoggerBase <T> requestDetailsLoggerBase = RequestDetailsLoggerBase <T> .InitializeRequestLogger(activityScope); ServiceCommonMetadataPublisher.PublishServerInfo(requestDetailsLoggerBase.ActivityScope); requestDetailsLoggerBase.Commit(); } }
public static void SetCurrent(HttpContext httpContext, T logger) { if (httpContext != null && httpContext.Items != null) { httpContext.Items[RequestDetailsLoggerBase <T> .ContextItemKey] = logger; return; } if (RequestDetailsLoggerBase <T> .AdditionalLoggerSetterForSetCurrent != null) { RequestDetailsLoggerBase <T> .AdditionalLoggerSetterForSetCurrent(logger); } }
public static T GetCurrent(HttpContext httpContext) { if (httpContext != null && httpContext.Items != null) { return((T)((object)httpContext.Items[RequestDetailsLoggerBase <T> .ContextItemKey])); } if (RequestDetailsLoggerBase <T> .AdditionalLoggerGetterForGetCurrent != null) { return(RequestDetailsLoggerBase <T> .AdditionalLoggerGetterForGetCurrent()); } return(default(T)); }
public static string[] GetColumnNames() { RequestLoggerConfig config = RequestDetailsLoggerBase <T> .GetConfig(); string[] array = new string[config.Columns.Count]; int num = 0; foreach (KeyValuePair <string, Enum> keyValuePair in config.Columns) { array[num++] = keyValuePair.Key; } return(array); }
private static void SafeInitializeLogger(RequestDetailsLoggerBase <T> requestDetailsLoggerBase) { if (!RequestDetailsLoggerBase <T> .IsInitialized) { lock (RequestDetailsLoggerBase <T> .staticSyncRoot) { if (!RequestDetailsLoggerBase <T> .IsInitialized) { requestDetailsLoggerBase.InitializeLogger(); RequestDetailsLoggerBase <T> .IsInitialized = true; } } } }
public void PushDebugInfoToResponseHeaders(HttpContext httpContext) { if (httpContext != null && this.ShouldSendDebugResponseHeaders()) { RequestDetailsLoggerBase <T> .SafeLogOperation <string, string>(this, string.Empty, string.Empty, delegate(RequestDetailsLoggerBase <T> logger, string k, string v) { logger.AddToResponseHeadersIfAvailable(httpContext, ServiceCommonMetadata.LiveIdBasicError); logger.AddToResponseHeadersIfAvailable(httpContext, ServiceCommonMetadata.LiveIdBasicLog); logger.AddToResponseHeadersIfAvailable(httpContext, ServiceCommonMetadata.LiveIdNegotiateError); logger.AddToResponseHeadersIfAvailable(httpContext, ServiceCommonMetadata.OAuthError); logger.AddToResponseHeadersIfAvailable(httpContext, ServiceCommonMetadata.GenericInfo); logger.AddToResponseHeadersIfAvailable(httpContext, ServiceCommonMetadata.AuthenticationErrors); logger.AddToResponseHeadersIfAvailable(httpContext, ServiceCommonMetadata.GenericErrors); }); } }
private void InitializeRequest(IActivityScope activityScope) { RequestDetailsLoggerBase <T> .SafeInitializeLogger(this); lock (this.SyncRoot) { if (this.ActivityScope == null) { if (activityScope == null) { this.ActivityScope = ActivityContext.Start(null); } else { this.ActivityScope = activityScope; } this.Row = new LogRowFormatter(RequestDetailsLoggerBase <T> .LogSchema); } } }
protected void LogExceptionToGenericError(Exception ex, string keyPrefix) { if (!RequestDetailsLoggerBase <T> .ProcessExceptionMessage) { this.ActivityScope.SetProperty(ServiceCommonMetadata.GenericErrors, ex.ToString()); string fullName = ex.GetType().FullName; this.ActivityScope.SetProperty(ServiceCommonMetadata.ExceptionName, fullName); string correctServerNameFromExceptionIfNecessary = RequestDetailsLoggerBase <T> .GetCorrectServerNameFromExceptionIfNecessary(fullName, ex); if (!string.IsNullOrWhiteSpace(correctServerNameFromExceptionIfNecessary)) { this.ActivityScope.SetProperty(ServiceCommonMetadata.CorrectBEServerToUse, correctServerNameFromExceptionIfNecessary); } return; } if (this.LogFullException(ex)) { this.AppendGenericError(keyPrefix, ex.ToString()); return; } this.AppendGenericError(keyPrefix + "_Type", ex.GetType().Name); this.AppendGenericError(keyPrefix + "_Message", ex.Message); this.AppendGenericError(keyPrefix + "_OuterStackTrace", ex.StackTrace); }
private static void SafeLogOperation <TKey, TValue>(RequestDetailsLoggerBase <T> requestDetailsLogger, TKey key, TValue value, RequestDetailsLoggerBase <T> .LogOperation <TKey, TValue> logOperation) { if (requestDetailsLogger == null || requestDetailsLogger.IsDisposed || key == null || value == null) { return; } try { if (Monitor.TryEnter(requestDetailsLogger.SyncRoot)) { if (!requestDetailsLogger.IsDisposed) { logOperation(requestDetailsLogger, key, value); } } } finally { if (Monitor.IsEntered(requestDetailsLogger.SyncRoot)) { Monitor.Exit(requestDetailsLogger.SyncRoot); } } }
public static T InitializeRequestLogger() { return(RequestDetailsLoggerBase <T> .InitializeRequestLogger(null)); }
public void AppendGenericError(string key, string value) { RequestDetailsLoggerBase <T> .SafeAppendGenericError(this, key, value); }
protected override void InternalDispose(bool disposing) { if (!this.isDisposeAlreadyCalled && disposing && this.ActivityScope != null) { lock (this.SyncRoot) { if (!this.isDisposeAlreadyCalled) { this.excludeLogEntry |= this.SkipLogging; try { if (this.ActivityScope.ActivityType == ActivityType.Request) { this.FetchLatencyData(); if (!this.excludeLogEntry) { this.PreCommitTasks(); } } if (this.EndActivityContext && this.ActivityScope.Status == ActivityContextStatus.ActivityStarted) { this.ActivityScope.End(); } if (!this.excludeLogEntry) { List <KeyValuePair <string, object> > formattableMetadata = this.ActivityScope.GetFormattableMetadata(); formattableMetadata.RemoveAll(delegate(KeyValuePair <string, object> pair) { Enum @enum = ActivityContext.LookupEnum(pair.Key); return(object.Equals(@enum, RequestDetailsLoggerBase <T> .RequestLoggerConfig.GenericInfoColumn) || object.Equals(@enum, ActivityStandardMetadata.ReturnClientRequestId) || RequestDetailsLoggerBase <T> .enumToIndexMap.ContainsKey(@enum)); }); List <KeyValuePair <string, object> > collection = WorkloadManagementLogger.FormatWlmActivity(this.ActivityScope, false); formattableMetadata.AddRange(collection); foreach (KeyValuePair <Enum, int> keyValuePair in RequestDetailsLoggerBase <T> .enumToIndexMap) { string text = this.Get(keyValuePair.Key); if (object.Equals(RequestDetailsLoggerBase <T> .RequestLoggerConfig.GenericInfoColumn, keyValuePair.Key)) { text += LogRowFormatter.FormatCollection(formattableMetadata); } if (!string.IsNullOrEmpty(text)) { text = RequestDetailsLoggerBase <T> .FormatForCsv(text); this.Row[keyValuePair.Value] = text; } } RequestDetailsLoggerBase <T> .Log.Append(this.Row, -1); this.UploadDataToStreamInsight(); } } finally { if (this.ActivityScope != null && this.EndActivityContext && this.ActivityScope.Status == ActivityContextStatus.ActivityStarted) { this.ActivityScope.End(); } this.isDisposeAlreadyCalled = true; } } } } }
public static void SafeAppendDetailedExchangePrincipalLatency(RequestDetailsLoggerBase <T> requestDetailsLogger, string key, string value) { RequestDetailsLoggerBase <T> .SafeAppendColumn(requestDetailsLogger, ServiceLatencyMetadata.DetailedExchangePrincipalLatency, key, value); }
public void AppendGenericInfo(string key, object value) { RequestDetailsLoggerBase <T> .SafeAppendGenericInfo(this, key, value); }
protected static void SafeAppendBackEndGenericInfo(RequestDetailsLoggerBase <T> requestDetailsLogger, string key, string value) { RequestDetailsLoggerBase <T> .SafeAppendColumn(requestDetailsLogger, ServiceCommonMetadata.BackEndGenericInfo, key, value); }
public static void SafeAppendGenericError(RequestDetailsLoggerBase <T> requestDetailsLogger, string key, string value) { RequestDetailsLoggerBase <T> .SafeAppendColumn(requestDetailsLogger, ServiceCommonMetadata.GenericErrors, key, value); }