If an error occurred in report processing, JavaScript Report Viewer displays short messages about the error in view. You need to configure the ApiController
to save all logs, stack trace, and error information.
This section explains how to log the detailed error information to your JavaScript application.
This section requires a JavaScript Report Viewer application, if you don’t have, then create by referring to the Getting-Started documentation.
In Solution Explorer, open the Report Viewer Controller file.
Inherit the IReportLogger
interface and implement the interface methods.
public class ReportViewerController : ApiController, IReportController, IReportLogger
{
public void LogError(string message, Exception exception, MethodBase methodType, ErrorType errorType)
{
throw new NotImplementedException();
}
public void LogError(string errorCode, string message, Exception exception, string errorDetail, string methodName, string className)
{
throw new NotImplementedException();
}
}
Create a method in ReportViewerController
to write the error text into application folder.
internal void WriteLogs(string errorMessage)
{
string filePath = HttpContext.Current.Server.MapPath("/App_Data/ErrorDetails.txt");
using (StreamWriter writer = new StreamWriter(filePath, true))
{
writer.AutoFlush = true;
writer.WriteLine(errorMessage);
}
}
Invoke the newly created function in LogError
as follows.
public void LogError(string message, Exception exception, MethodBase methodType, ErrorType errorType)
{
WriteLogs(string.Format("Error Message: {0} \n Stack Trace: {1}", message, exception.StackTrace));
}
public void LogError(string errorCode, string message, Exception exception, string errorDetail, string methodName, string className)
{
WriteLogs(string.Format("Class Name: {0} \n Method Name: {1} \n Error Message: {2} \n Stack Trace: {3}", className, methodName, errorDetail, exception.StackTrace));
}
In cases of any issues faced in the report rendering, share the log file to our technical support team to get assistance on that.
The final controller is given as follows, you can replace it in your application.
public class ReportViewerController : ApiController, IReportController, IReportLogger
{
// Post action for processing the RDL/RDLC report
public object PostReportAction(Dictionary<string, object> jsonResult)
{
return ReportHelper.ProcessReport(jsonResult, this);
}
// Get action for getting resources from the report
[System.Web.Http.ActionName("GetResource")]
[AcceptVerbs("GET")]
public object GetResource(string key, string resourcetype, bool isPrint)
{
return ReportHelper.GetResource(key, resourcetype, isPrint);
}
// Method that will be called when initialize the report options before start processing the report
[NonAction]
public void OnInitReportOptions(ReportViewerOptions reportOption)
{
// You can update report options here
}
// Method that will be called when reported is loaded
[NonAction]
public void OnReportLoaded(ReportViewerOptions reportOption)
{
// You can update report options here
}
public void LogError(string message, Exception exception, MethodBase methodType, ErrorType errorType)
{
WriteLogs(string.Format("Error Message: {0} \n Stack Trace: {1}", message, exception.StackTrace));
}
public void LogError(string errorCode, string message, Exception exception, string errorDetail, string methodName, string className)
{
WriteLogs(string.Format("Class Name: {0} \n Method Name: {1} \n Error Message: {2} \n Stack Trace: {3}", className, methodName, message, exception.StackTrace));
}
internal void WriteLogs(string errorMessage)
{
// Error details text file path location
string filePath = HttpContext.Current.Server.MapPath("/App_Data/ErrorDetails.txt");
using (StreamWriter writer = new StreamWriter(filePath, true))
{
writer.AutoFlush = true;
writer.WriteLine(errorMessage);
}
}
}