Monitoring the SDK Internal Events

Do you want to know what's happening the inside and do you want to tap into it?

Monitor any internal event regardless of the specific instance of the Logger

  1. Get a reference to the RollbarQueueController.Instance singleton.
  2. Subscribe to its InternalEvent event.
  3. Implement the event handler as you desire. As the result of this subscription, at runtime, all the Rollbar internal events generated while using any instance of the Notifier will be reported into the event handler.

Monitor internal events within any specific instance of the Logger

  1. Get a reference to a specific instance of the Notifier.
  2. Subscribe to its InternalEvent event.
  3. Implement the event handler as you desire. As the result of this subscription, at runtime, all the Rollbar internal events generated while using this specific instance of the Notifier will be reported into the event handler.

Code Sample

static void Main(string[] args)
{
  ConfigureRollbarSingleton();

  RollbarLocator.RollbarInstance
    .Info("ConsoleApp sample: Basic info log example.");
  RollbarLocator.RollbarInstance
    .Debug("ConsoleApp sample: First debug log.");
  RollbarLocator.RollbarInstance
    .Error(new Exception("ConsoleApp sample: null reference exception."));
  RollbarLocator.RollbarInstance
    .Error(new Exception("ConsoleApp sample: outer", new Exception("inner")));

  System.Threading.Thread.Sleep(TimeSpan.FromSeconds(10));
}

/// <summary>
/// Configures the Rollbar singleton-like notifier.
/// </summary>
private static void ConfigureRollbarSingleton()
{
  const string rollbarAccessToken = "POST_SERVER_ITEM_ACCESS_TOKEN";
  const string rollbarEnvironment = "RollbarNetSamples";

  var config = new RollbarConfig(rollbarAccessToken) // minimally required
  {
    Environment = rollbarEnvironment,
    ScrubFields = new string[]
    {
      "pw",
      "username",
    }
  };
  RollbarLocator.RollbarInstance
    // minimally required Rollbar configuration:
    .Configure(config)
    // if you would like to monitor Rollbar internal events of this logger:
    .InternalEvent += OnRollbarInternalEvent
    ;

  // Optional info about reporting Rollbar user:
  SetRollbarReportingUser("007", "[email protected]", "JBOND");
}

/// <summary>
/// Sets the rollbar reporting user.
/// </summary>
/// <param name="id">The identifier.</param>
/// <param name="email">The email.</param>
/// <param name="userName">Name of the user.</param>
private static void SetRollbarReportingUser(string id, string email, string userName)
{
  Person person = new Person(id);
  person.Email = email;
  person.UserName = userName;
  RollbarLocator.RollbarInstance.Config.Person = person;
}

/// <summary>
/// Called when rollbar internal event is detected.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="RollbarEventArgs"/> instance containing the event data.</param>
private static void OnRollbarInternalEvent(object sender, RollbarEventArgs e)
{
  Console.WriteLine(e.TraceAsString());

  RollbarApiErrorEventArgs apiErrorEvent = e as RollbarApiErrorEventArgs;
  if (apiErrorEvent != null)
  {
    //TODO: handle/report Rollbar API communication error event...
    return;
  }
  CommunicationEventArgs commEvent = e as CommunicationEventArgs;
  if (commEvent != null)
  {
    //TODO: handle/report Rollbar API communication event...
    return;
  }
  CommunicationErrorEventArgs commErrorEvent = e as CommunicationErrorEventArgs;
  if (commErrorEvent != null)
  {
    //TODO: handle/report basic communication error while attempting to reach 
    //      Rollbar API service... 
    return;
  }
  InternalErrorEventArgs internalErrorEvent = e as InternalErrorEventArgs;
  if (internalErrorEvent != null)
  {
    //TODO: handle/report basic internal error... 
    return;
  }
}