Is there a way to retrieve the created Rollbar item when logging an error on C#?

90 views Asked by At

I want to add a Rollbar link to the errors returned by my Rollbar middleware for my dev environment.

Currently, I'm using a very simple Rollbar logging system

var ret = RollbarLocator.RollbarInstance.Error(ex);
1

There are 1 answers

0
Nico Kruger On

You can add any number of custom data items to the Rollbar Payload in C# (DOT NET).

Example:

            RollbarLoggerConfig rollbarConfig = new RollbarLoggerConfig(rollbarAccessToken, rollbarEnvironment);
            string json;
            Dictionary<string, object> dictionary;

            json = JsonConvert.SerializeObject(logObject);
            dictionary = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);


            RollbarPayloadManipulationOptions rollbarPayload = new RollbarPayloadManipulationOptions()
            {
                Transform = payload => {
                    payload.Data.Custom = dictionary;
                    payload.Data.Environment = rollbarEnvironment;
                }
            };
            RollbarLocator.RollbarInstance.Configure(rollbarConfig); 
            RollbarLocator.RollbarInstance.Error(ex, dictionary);

Now once you have sent an Error to Rollbar the Rollbar item (payload contains a UUID).

Use that UUID to generate a URL directly to Rollbar or show a message in your app that a user can use the UUID to contact support and internally you can look up the Rollbar error using the UUID like this.

One for the Items (Example): rollbar.com/item/uuid/?uuid=aaaaaaaa-bbbb-cccc-dddd-eeeeffffeeee

Another for the Occurrences (Example): rollbar.com/occurrence/uuid/?uuid=aaaaaaaa-bbbb-cccc-dddd-eeeeffffeeee

Read more here: https://docs.rollbar.com/docs/finding-items-by-uuid