/// <summary> /// Packages as payload data. /// </summary> /// <param name="utcTimestamp">The UTC timestamp of when the object-to-log was captured.</param> /// <param name="rollbarConfig">The rollbar configuration.</param> /// <param name="level">The level.</param> /// <param name="obj">The object.</param> /// <param name="custom">The custom.</param> /// <returns>Data.</returns> public static Data PackageAsPayloadData( DateTime utcTimestamp, IRollbarConfig rollbarConfig, ErrorLevel level, object obj, IDictionary <string, object> custom = null ) { if (rollbarConfig.LogLevel.HasValue && level < rollbarConfig.LogLevel.Value) { // nice shortcut: return(null); } Data data = obj as Data; if (data != null) { //we do not have to update the timestamp of the data here //because we already have the incoming object to log of DTOs.Data type //so the timestamp value assigned during its construction should work better: data.Level = level; return(data); } IRollbarPackage rollbarPackagingStrategy = obj as IRollbarPackage; if (rollbarPackagingStrategy != null) { data = rollbarPackagingStrategy.PackageAsRollbarData(); if (data != null) { data.Environment = rollbarConfig?.Environment; data.Level = level; //update the data timestamp from the data creation timestamp to the passed //object-to-log capture timestamp: data.Timestamp = DateTimeUtil.ConvertToUnixTimestampInSeconds(utcTimestamp); } return(data); } Body body = obj as Body; if (body == null) { body = RollbarUtility.PackageAsPayloadBody(obj, ref custom); } data = new Data(rollbarConfig, body, custom); data.Level = level; //update the data timestamp from the data creation timestamp to the passed //object-to-log capture timestamp: data.Timestamp = DateTimeUtil.ConvertToUnixTimestampInSeconds(utcTimestamp); return(data); }
internal ILogger Enqueue( object dataObject, ErrorLevel level, IDictionary <string, object> custom, TimeSpan?timeout = null, SemaphoreSlim signal = null ) { // here is the last chance to decide if we need to actually send this payload // based on the current config settings: if (string.IsNullOrWhiteSpace(this._config.AccessToken) || this._config.Enabled == false || (this._config.LogLevel.HasValue && level < this._config.LogLevel.Value) ) { // nice shortcut: return(this); } DateTime?timeoutAt = null; if (timeout.HasValue) { timeoutAt = DateTime.Now.Add(timeout.Value); } PayloadBundle payloadBundle = null; IRollbarPackage rollbarPackage = dataObject as IRollbarPackage; if (rollbarPackage != null) { if (rollbarPackage.MustApplySynchronously) { rollbarPackage.PackageAsRollbarData(); } payloadBundle = new PayloadBundle(this.Config, rollbarPackage, level, custom, timeoutAt, signal); } else { payloadBundle = new PayloadBundle(this.Config, dataObject, level, custom, timeoutAt, signal); } if (payloadBundle == null) { //TODO: we may want to report that there is some problem with packaging... return(this); } this._payloadQueue.Enqueue(payloadBundle); return(this); }
/// <summary> /// Gets the payload data. /// </summary> /// <returns>Data.</returns> private Data GetPayloadData() { Data data; IRollbarPackage rollbarPackage = GetRollbarPackage(); Assumption.AssertNotNull(rollbarPackage, nameof(rollbarPackage)); data = rollbarPackage.PackageAsRollbarData(); Assumption.AssertNotNull(data, nameof(data)); return(data); }
/// <summary> /// Creates the payload bundle. /// </summary> /// <param name="dataObject">The data object.</param> /// <param name="level">The level.</param> /// <param name="custom">The custom.</param> /// <param name="timeout">The timeout.</param> /// <param name="signal">The signal.</param> /// <returns>PayloadBundle.</returns> private PayloadBundle CreatePayloadBundle( object dataObject, ErrorLevel level, IDictionary <string, object> custom, TimeSpan?timeout = null, SemaphoreSlim signal = null ) { DateTime?timeoutAt = null; if (timeout.HasValue) { timeoutAt = DateTime.Now.Add(timeout.Value); } PayloadBundle payloadBundle = null; IRollbarPackage rollbarPackage = dataObject as IRollbarPackage; if (rollbarPackage != null) { if (rollbarPackage.MustApplySynchronously) { rollbarPackage.PackageAsRollbarData(); } payloadBundle = new PayloadBundle(this, rollbarPackage, level, custom, timeoutAt, signal); } else { payloadBundle = new PayloadBundle(this, dataObject, level, custom, timeoutAt, signal); } return(payloadBundle); }