/// <summary> /// Set success value from a passed in status code /// </summary> /// <param name="statusCode">status code to set success value from</param> /// <remarks>500 or above is considered failure, /// all other values considered success. However, if the success value is already set, /// calling this method does not override the success value. /// The status code is stored on the scope in any case.</remarks> public void SetSuccessFromStatusCode(HttpStatusCode statusCode) { if (!IsSuccessful.HasValue) { IsSuccessful = (uint)statusCode < (uint)HttpStatusCode.InternalServerError; } if (string.IsNullOrWhiteSpace(TimedScopeData.Data(TimedScopeDataKeys.InternalOnly.StatusCode))) { AddLoggingValue(TimedScopeDataKeys.InternalOnly.StatusCode, statusCode.ToString()); } }
/// <summary> /// Adds the given key and value to the context of the timed scope /// </summary> /// <param name="key">Key of the item to be added.</param> /// <param name="value">Value of the item to be added.</param> /// <param name="overrideValue">Whether the value should be overriden</param> public void AddLoggingValue(string key, string value, bool overrideValue = false) { if (string.IsNullOrWhiteSpace(key)) { ULSLogging.LogTraceTag(0x238174e1 /* tag_96xt7 */, Categories.TimingGeneral, Levels.Error, "Empty or null key detected when attempting to add an entry in the timed scope data dictionary. Key : '{0}'.", key ?? "<NULL>"); return; } string existingValue = TimedScopeData.Data(key); if (existingValue != null && !overrideValue) { ULSLogging.LogTraceTag(0x238174e2 /* tag_96xt8 */, Categories.TimingGeneral, Levels.Warning, "Timed scope data dictionary already contains key '{0}' with value '{1}'.", key, existingValue); } else { TimedScopeData.AddData(key, value ?? string.Empty); } }