/// <summary> /// Produces the rollbar data. /// </summary> /// <returns>Rollbar Data DTO or null (if packaging is not applicable in some cases).</returns> protected override Data ProduceRollbarData() { Data data = null; switch (this._objectToPackage) { case Data dataObj: data = dataObj; break; case IRollbarPackage rollbarPackageObj: data = rollbarPackageObj.PackageAsRollbarData(); break; default: Body body = this._objectToPackage as Body; if (body == null) { body = RollbarUtility.PackageAsPayloadBody(this._objectToPackage, ref this._custom); } data = new Data(null, body, this._custom); break; } if (!string.IsNullOrWhiteSpace(this._rollbarDataTitle)) { data.Title = this._rollbarDataTitle; } return(data); }
/// <summary> /// Packages as payload body. /// </summary> /// <param name="bodyObject">The body object.</param> /// <param name="custom">The custom.</param> /// <returns>Body.</returns> public static Body PackageAsPayloadBody(object bodyObject, ref IDictionary <string, object> custom) { System.Exception exception = bodyObject as System.Exception; if (exception != null) { RollbarUtility.SnapExceptionDataAsCustomData(exception, ref custom); return(new Body(exception)); } string messageString = bodyObject as string; if (messageString != null) { return(new Body(new Message(messageString))); } ITraceable traceable = bodyObject as ITraceable; if (traceable != null) { return(new Body(traceable.TraceAsString())); } return(new Body(new Message(bodyObject.ToString()))); }
/// <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); }
/// <summary> /// Produces the rollbar data. /// </summary> /// <returns>Rollbar Data DTO or null (if packaging is not applicable in some cases).</returns> protected override Data ProduceRollbarData() { Body rollbarBody = new Body(this._exceptionToPackage); IDictionary <string, object?>?custom = null; RollbarUtility.SnapExceptionDataAsCustomData(this._exceptionToPackage, ref custom); Data rollbarData = new Data(rollbarBody, custom); rollbarData.Title = this._rollbarDataTitle; return(rollbarData); }