Integrating with WPF based Applications

It is optional to set the user for Rollbar, and this can be reset to a different user at any time. This example includes a default user being set with MainWindow.xml loads by calling the SetRollbarReportingUser function. Gist example code here.

In App.cs:

namespace Sample
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App 
      : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            System.Diagnostics.Debug.WriteLine("App Start Up");

            //Initialize Rollbar
            RollbarLocator.RollbarInstance.Configure(new RollbarConfig
            {
                AccessToken = "POST_SERVER_ITEM_ACCESS_TOKEN",
                Environment = "production"          
            });
            // Setup Exception Handler
            AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
            {
                RollbarLocator.RollbarInstance.Error(
                  args.ExceptionObject as System.Exception
                );
            };
        }
    }
}

In MainWindow.cs:

namespace Sample
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow 
      : Window
    {
        public MainWindow()
        {
            System.Diagnostics.Debug.Write("Starting MainWindow");

            InitializeComponent();

            //Set Default User for RollbarReporting
            //  -- Reset if user logs in 
            //     or wait to call SetRollbarReportingUser until user logs in. 
            SetRollbarReportingUser("id", "[email protected]", "default");
        }

        private void SetRollbarReportingUser(
          string id, 
          string email, 
          string userName)
        {
            Person person = new Person(id);
            person.Email = email;
            person.UserName = userName;
            RollbarLocator.RollbarInstance.Config.Person = person;
        }
    }
}