Search results
Suggest a FeaturePDF

Error logging in UWP Report Viewer

If an error occurred in report processing, UWP Report Viewer displays short messages about the error in view. In report viewer Reporterror event raised. You can register the event and get the report error details from the event arguments to save all logs and error information into a physical file location.

This section explains how to log the detailed error information to your UWP application.

This section requires a UWP Report Viewer application, if you don’t have then create using the Getting-Started.

  1. In Solution Explorer, Open report viewer initialization cs file.

  2. Register the ReportError event.

    private void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        this.ReportViewer.ReportError += ReportViewer_ReportError;
    }
    private void ReportViewer_ReportError(object sender, ReportErrorEventArgs e)
    {
        // You can register the report errors using event arguments.
    }
    
  3. Create a method in MainPage.xaml.cs to write the error text into application folder.

        private async void WriteLogs(string errorMessage)
        {
            var appFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
            //you can refer to your preferred location path for errordetails text file.
            var filePath = await appFolder.CreateFileAsync("Errordetails.txt", Windows.Storage.CreationCollisionOption.OpenIfExists);
            await Windows.Storage.FileIO.AppendTextAsync(filePath, errorMessage + Environment.NewLine);
        }
  4. Invoke the newly created function in ReportViewer_ReportError as follows.

        private void ReportViewer_ReportError(object sender, ReportErrorEventArgs e)
        {
            string errorLog;
    
            if (e.Exception != null)
            {
                errorLog = (string.Format("Error Message: {0} \n Stack Trace: {1}", e.Message, e.Exception.StackTrace));
            }
            else
            {
                errorLog = e.Message;
            }
    
            WriteLogs(errorLog);
        }

    In cases of any issues faced in the report rendering, share the log file to our technical support team to get assistance on that.

  5. The final MainPage.xaml.cs file is given as follows, you can replace it in your application.

    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
            this.Loaded += MainPage_Loaded;
        }
    
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            this.ReportViewer.ReportPath = "~/Resources/docs/sales-order-dtail.rdl";
            this.ReportViewer.ReportServiceURL = @"https://demos.boldreports.com/services/api/ReportViewer";
            this.ReportViewer.ReportError += ReportViewer_ReportError;
            this.ReportViewer.RefreshReport();
        }
    
        private void ReportViewer_ReportError(object sender, ReportErrorEventArgs e)
        {
            string errorLog;
    
            if (e.Exception != null)
            {
                errorLog = (string.Format("Error Message: {0} \n Stack Trace: {1}", e.Message, e.Exception.StackTrace));
            }
            else
            {
                errorLog = e.Message;
            }
    
            WriteLogs(errorLog);
        }
    
        private async void WriteLogs(string errorMessage)
        {
            var appFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
            //you can refer to your preferred location path for errordetails text file.
            var filePath = await appFolder.CreateFileAsync("Errordetails.txt", Windows.Storage.CreationCollisionOption.OpenIfExists);
            await Windows.Storage.FileIO.AppendTextAsync(filePath, errorMessage + Environment.NewLine);
        }
    }
Having trouble getting help?
Contact Support
Having trouble getting help?
Contact Support