/// <summary> /// Initializes a new instance of the <see cref="ConfigAttributesPackageDecorator"/> class. /// </summary> /// <param name="packageToDecorate">The package to decorate.</param> /// <param name="rollbarConfig">The rollbar configuration.</param> public ConfigAttributesPackageDecorator( IRollbarPackage packageToDecorate, IRollbarConfig rollbarConfig ) : this(packageToDecorate, rollbarConfig, false) { }
/// <summary> /// Decorates the specified rollbar data. /// </summary> /// <param name="rollbarData">The rollbar data.</param> protected override void Decorate(Data rollbarData) { IRollbarPackage package = this._packageToDecorate; if (this._httpContext?.Request != null) { // here we essentially piggy-back on capabilities of // already implemented HttpRequestPackageDecorator // instead of this decorator: package = new HttpRequestPackageDecorator(package, this._httpContext.Request); } if (this._httpContext?.Response != null) { // here we essentially piggy-back on capabilities of // already implemented HttpResponsePackageDecorator // instead of this decorator: package = new HttpResponsePackageDecorator(package, this._httpContext.Response); } if (package != this._packageToDecorate) { package.PackageAsRollbarData(); } }
/// <summary> /// Initializes a new instance of the <see cref="RollbarHttpContextPackageDecorator"/> class. /// </summary> /// <param name="packageToDecorate">The package to decorate.</param> /// <param name="rollbarHttpContext">The rollbar HTTP context.</param> public RollbarHttpContextPackageDecorator( IRollbarPackage packageToDecorate, RollbarHttpContext rollbarHttpContext ) : this(packageToDecorate, rollbarHttpContext, false) { }
/// <summary> /// Gets the rollbar package. /// </summary> /// <returns>IRollbarPackage.</returns> private IRollbarPackage GetRollbarPackage() { IRollbarPackage rollbarPackage = CreateRollbarPackage(); rollbarPackage = ApplyConfigPackageDecorator(rollbarPackage); return(rollbarPackage); }
/// <summary> /// Initializes a new instance of the <see cref="RollbarPackageDecoratorBase" /> class. /// </summary> /// <param name="packageToDecorate">The package to decorate.</param> /// <param name="mustApplySynchronously">if set to <c>true</c> the strategy must be apply synchronously.</param> protected RollbarPackageDecoratorBase(IRollbarPackage packageToDecorate, bool mustApplySynchronously) : base(mustApplySynchronously) { Assumption.AssertNotNull(packageToDecorate, nameof(packageToDecorate)); this._packageToDecorate = packageToDecorate; }
/// <summary> /// Initializes a new instance of the <see cref="HttpRequestPackageDecorator" /> class. /// </summary> /// <param name="packageToDecorate">The package to decorate.</param> /// <param name="httpRequest">The HTTP request.</param> public HttpRequestPackageDecorator(IRollbarPackage packageToDecorate, HttpRequestBase httpRequest) : base(packageToDecorate, false) { Assumption.AssertNotNull(httpRequest, nameof(httpRequest)); this._httpRequest = httpRequest; }
/// <summary> /// Initializes a new instance of the <see cref="HttpRequestPackageDecorator"/> class. /// </summary> /// <param name="packageToDecorate">The package to decorate.</param> /// <param name="httpRequest">The HTTP request.</param> /// <param name="mustApplySynchronously">if set to <c>true</c> [must apply synchronously].</param> public HttpRequestPackageDecorator(IRollbarPackage packageToDecorate, HttpRequestBase httpRequest, bool mustApplySynchronously) : base(packageToDecorate, mustApplySynchronously) { Assumption.AssertNotNull(httpRequest, nameof(httpRequest)); this._httpRequest = httpRequest; }
/// <summary> /// Initializes a new instance of the <see cref="HttpResponsePackageDecorator"/> class. /// </summary> /// <param name="packageToDecorate">The package to decorate.</param> /// <param name="httpResponse">The HTTP response.</param> /// <param name="mustApplySynchronously">if set to <c>true</c> [must apply synchronously].</param> public HttpResponsePackageDecorator(IRollbarPackage packageToDecorate, HttpResponseBase httpResponse, bool mustApplySynchronously) : base(packageToDecorate, mustApplySynchronously) { Assumption.AssertNotNull(httpResponse, nameof(httpResponse)); this._httpResponse = httpResponse; }
/// <summary> /// Initializes a new instance of the <see cref="CustomKeyValuePackageDecorator"/> class. /// </summary> /// <param name="packageToDecorate">The package to decorate.</param> /// <param name="custom">The custom.</param> public CustomKeyValuePackageDecorator( IRollbarPackage packageToDecorate, IDictionary <string, object?>?custom ) : this(packageToDecorate, custom, false) { }
/// <summary> /// Initializes a new instance of the <see cref="PayloadBundle" /> class. /// </summary> /// <param name="rollbarLogger">The rollbar logger.</param> /// <param name="payloadPackage">The payload package.</param> /// <param name="level">The level.</param> public PayloadBundle( RollbarLogger rollbarLogger, IRollbarPackage payloadPackage, ErrorLevel level ) : this(rollbarLogger, payloadPackage, level, null, null, null) { }
/// <summary> /// Initializes a new instance of the <see cref="HttpRequestMessagePackageDecorator"/> class. /// </summary> /// <param name="packageToDecorate">The package to decorate.</param> /// <param name="httpRequestMessage">The HTTP request message.</param> /// <param name="rollbarConfig">The rollbar configuration.</param> public HttpRequestMessagePackageDecorator( IRollbarPackage packageToDecorate, HttpRequestMessage httpRequestMessage, IRollbarConfig rollbarConfig ) : this(packageToDecorate, httpRequestMessage, rollbarConfig, null, false) { }
/// <summary> /// Initializes a new instance of the <see cref="PersonPackageDecorator" /> class. /// </summary> /// <param name="packageToDecorate">The package to decorate.</param> /// <param name="person">The person.</param> public PersonPackageDecorator( IRollbarPackage packageToDecorate, Person person ) : base(packageToDecorate, false) { this._person = person; }
/// <summary> /// Initializes a new instance of the <see cref="PayloadBundle"/> class. /// </summary> /// <param name="rollbarConfig">The rollbar configuration.</param> /// <param name="payloadPackage">The payload package.</param> /// <param name="level">The level.</param> public PayloadBundle( IRollbarConfig rollbarConfig, IRollbarPackage payloadPackage, ErrorLevel level ) : this(rollbarConfig, payloadPackage, level, null, null, null) { }
/// <summary> /// Applies the configuration package decorator. /// </summary> /// <param name="packageToDecorate">The package to decorate.</param> /// <returns>IRollbarPackage.</returns> private IRollbarPackage ApplyConfigPackageDecorator(IRollbarPackage packageToDecorate) { if (this._rollbarLogger.Config == null) { return(packageToDecorate); // nothing to decorate with } return(new ConfigAttributesPackageDecorator(packageToDecorate, this._rollbarLogger.Config)); }
/// <summary> /// Initializes a new instance of the <see cref="RollbarHttpContextPackageDecorator"/> class. /// </summary> /// <param name="packageToDecorate">The package to decorate.</param> /// <param name="rollbarHttpContext">The rollbar HTTP context.</param> /// <param name="mustApplySynchronously">if set to <c>true</c> [must apply synchronously].</param> public RollbarHttpContextPackageDecorator( IRollbarPackage packageToDecorate, RollbarHttpContext rollbarHttpContext, bool mustApplySynchronously ) : base(packageToDecorate, mustApplySynchronously) { this._rollbarHttpContext = rollbarHttpContext; }
/// <summary> /// Initializes a new instance of the <see cref="PayloadBundle" /> class. /// </summary> /// <param name="rollbarLogger">The rollbar logger.</param> /// <param name="payloadPackage">The payload package.</param> /// <param name="level">The level.</param> /// <param name="custom">The custom.</param> public PayloadBundle( RollbarLogger rollbarLogger, IRollbarPackage payloadPackage, ErrorLevel level, IDictionary <string, object> custom ) : this(rollbarLogger, payloadPackage, level, custom, null, null) { }
/// <summary> /// Initializes a new instance of the <see cref="HttpContextPackageDecorator"/> class. /// </summary> /// <param name="packageToDecorate">The package to decorate.</param> /// <param name="httpContext">The HTTP context.</param> /// <param name="mustApplySynchronously">if set to <c>true</c> [must apply synchronously].</param> public HttpContextPackageDecorator(IRollbarPackage packageToDecorate, HttpContextBase httpContext, bool mustApplySynchronously) : base(packageToDecorate, mustApplySynchronously) { Assumption.AssertNotNull(httpContext, nameof(httpContext)); this._httpContext = httpContext; this._packageToDecorate = packageToDecorate; }
/// <summary> /// Initializes a new instance of the <see cref="PersonPackageDecorator" /> class. /// </summary> /// <param name="packageToDecorate">The package to decorate.</param> /// <param name="personId">The person identifier.</param> /// <param name="personUsername">The person username.</param> /// <param name="personEmail">The person email.</param> public PersonPackageDecorator( IRollbarPackage packageToDecorate, string personId, string personUsername, string?personEmail = null ) : this(packageToDecorate, new Person(personId) { UserName = personUsername, Email = personEmail }) { }
/// <summary> /// Initializes a new instance of the <see cref="CustomKeyValuePackageDecorator"/> class. /// </summary> /// <param name="packageToDecorate">The package to decorate.</param> /// <param name="custom">The custom.</param> /// <param name="mustApplySynchronously">if set to <c>true</c> [must apply synchronously].</param> public CustomKeyValuePackageDecorator( IRollbarPackage packageToDecorate, IDictionary <string, object?>?custom, bool mustApplySynchronously ) : base(packageToDecorate, mustApplySynchronously) { this._custom = custom; }
/// <summary> /// Initializes a new instance of the <see cref="HttpContextPackageDecorator" /> class. /// </summary> /// <param name="packageToDecorate">The package to decorate.</param> /// <param name="httpContext">The HTTP context.</param> public HttpContextPackageDecorator(IRollbarPackage packageToDecorate, HttpContext httpContext) : base(packageToDecorate, false) { Assumption.AssertNotNull(httpContext, nameof(httpContext)); this._httpContext = httpContext; this._packageToDecorate = packageToDecorate; }
/// <summary> /// Applies the custom key value decorator. /// </summary> /// <param name="packageToDecorate">The package to decorate.</param> /// <returns>IRollbarPackage.</returns> private IRollbarPackage ApplyCustomKeyValueDecorator(IRollbarPackage packageToDecorate) { if (this._custom == null || this._custom.Count == 0) { return(packageToDecorate); // nothing to decorate with } return(new CustomKeyValuePackageDecorator(packageToDecorate, this._custom)); }
/// <summary> /// Initializes a new instance of the <see cref="HttpRequestMessagePackageDecorator"/> class. /// </summary> /// <param name="packageToDecorate">The package to decorate.</param> /// <param name="httpRequestMessage">The HTTP request message.</param> /// <param name="rollbarConfig">The rollbar configuration.</param> /// <param name="mustApplySynchronously">if set to <c>true</c> [must apply synchronously].</param> public HttpRequestMessagePackageDecorator( IRollbarPackage packageToDecorate, HttpRequestMessage httpRequestMessage, IRollbarConfig rollbarConfig, bool mustApplySynchronously ) : this(packageToDecorate, httpRequestMessage, rollbarConfig, null, mustApplySynchronously) { }
/// <summary> /// Initializes a new instance of the <see cref="HttpRequestMessagePackageDecorator"/> class. /// </summary> /// <param name="packageToDecorate">The package to decorate.</param> /// <param name="httpRequestMessage">The HTTP request message.</param> /// <param name="rollbarConfig">The rollbar configuration.</param> /// <param name="arbitraryKeyValuePairs">The arbitrary key value pairs.</param> public HttpRequestMessagePackageDecorator( IRollbarPackage packageToDecorate, HttpRequestMessage httpRequestMessage, IRollbarConfig rollbarConfig, IDictionary <string, object> arbitraryKeyValuePairs ) : this(packageToDecorate, httpRequestMessage, rollbarConfig, arbitraryKeyValuePairs, false) { }
/// <summary> /// Initializes a new instance of the <see cref="PayloadBundle" /> class. /// </summary> /// <param name="rollbarLogger">The rollbar logger.</param> /// <param name="payloadPackage">The payload package.</param> /// <param name="level">The level.</param> /// <param name="timeoutAt">The timeout at.</param> /// <param name="signal">The signal.</param> public PayloadBundle( RollbarLogger rollbarLogger, IRollbarPackage payloadPackage, ErrorLevel level, DateTime?timeoutAt, SemaphoreSlim signal ) : this(rollbarLogger, payloadPackage, level, null, timeoutAt, signal) { }
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> /// 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> /// 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> /// Composes the rolbar package. /// </summary> /// <typeparam name="TState">The type of the t state.</typeparam> /// <param name="eventId">The event identifier.</param> /// <param name="state">The state.</param> /// <param name="exception">The exception.</param> /// <param name="formatter">The formatter.</param> /// <returns>IRollbarPackage (if any) or null.</returns> protected virtual IRollbarPackage ComposeRolbarPackage <TState>( mslogging.EventId eventId , TState state , Exception exception , Func <TState, Exception, string> formatter ) { string message = null; if (formatter != null) { message = formatter(state, exception); } IRollbarPackage rollbarPackage = null; if (exception != null) { rollbarPackage = new ExceptionPackage(exception, exception.Message); } else if (!string.IsNullOrWhiteSpace(message)) { rollbarPackage = new MessagePackage(message, message); } else { return(null); //nothing to report... } Dictionary <string, object> customProperties = new Dictionary <string, object>(); customProperties.Add( "LogEventID" , $"{eventId.Id}" + (string.IsNullOrWhiteSpace(eventId.Name) ? string.Empty : $" ({eventId.Name})") ); if (exception != null && message != null) { customProperties.Add("LogMessage", message); } if (!string.IsNullOrWhiteSpace(this._name)) { customProperties.Add("RollbarLoggerName", this._name); } if (customProperties.Count > 0) { rollbarPackage = new CustomKeyValuePackageDecorator(rollbarPackage, customProperties); } return(rollbarPackage); }
/// <summary> /// Initializes a new instance of the <see cref="HttpRequestMessagePackageDecorator"/> class. /// </summary> /// <param name="packageToDecorate">The package to decorate.</param> /// <param name="httpRequestMessage">The HTTP request message.</param> /// <param name="rollbarConfig">The rollbar configuration.</param> /// <param name="arbitraryKeyValuePairs">The arbitrary key value pairs.</param> /// <param name="mustApplySynchronously">if set to <c>true</c> [must apply synchronously].</param> public HttpRequestMessagePackageDecorator( IRollbarPackage packageToDecorate, HttpRequestMessage httpRequestMessage, IRollbarConfig rollbarConfig, IDictionary <string, object> arbitraryKeyValuePairs, bool mustApplySynchronously ) : base(packageToDecorate, mustApplySynchronously) { Assumption.AssertNotNull(httpRequestMessage, nameof(httpRequestMessage)); Assumption.AssertNotNull(rollbarConfig, nameof(rollbarConfig)); this._httpRequestMessage = httpRequestMessage; this._rollbarConfig = rollbarConfig; this._arbitraryKeyValuePairs = arbitraryKeyValuePairs; }
/// <summary> /// Initializes a new instance of the <see cref="PayloadBundle" /> class. /// </summary> /// <param name="rollbarLogger">The rollbar logger.</param> /// <param name="payloadPackage">The payload package.</param> /// <param name="level">The level.</param> /// <param name="custom">The custom.</param> /// <param name="timeoutAt">The timeout at.</param> /// <param name="signal">The signal.</param> public PayloadBundle( RollbarLogger rollbarLogger, IRollbarPackage payloadPackage, ErrorLevel level, IDictionary <string, object> custom, DateTime?timeoutAt, SemaphoreSlim signal ) : this(rollbarLogger, payloadPackage as object, level, custom, timeoutAt, signal) { if (payloadPackage != null) { IRollbarPackage package = ApplyCustomKeyValueDecorator(payloadPackage); this._rollbarPackage = package; } }