diff --git a/AspNetCore.Reporting.Angular/AspNetCore.Reporting.Angular.Server/appsettings.json b/AspNetCore.Reporting.Angular/AspNetCore.Reporting.Angular.Server/appsettings.json index 30860e1..9793e74 100644 --- a/AspNetCore.Reporting.Angular/AspNetCore.Reporting.Angular.Server/appsettings.json +++ b/AspNetCore.Reporting.Angular/AspNetCore.Reporting.Angular.Server/appsettings.json @@ -6,6 +6,7 @@ "Logging": { "LogLevel": { "Default": "Warning", + "DevExpress": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } diff --git a/AspNetCore.Reporting.Common/Services/Reporting/ReportingLoggerService.cs b/AspNetCore.Reporting.Common/Services/Reporting/ReportingLoggerService.cs deleted file mode 100644 index 02fd060..0000000 --- a/AspNetCore.Reporting.Common/Services/Reporting/ReportingLoggerService.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using DevExpress.XtraReports.Web.ClientControls; -using Microsoft.Extensions.Logging; - -namespace AspNetCore.Reporting.Common.Services.Reporting { - public class ReportingLoggerService: LoggerService { - readonly ILogger logger; - public ReportingLoggerService(ILogger logger) { - this.logger = logger; - } - public override void Error(Exception exception, string message) { - var logMessage = $"[{DateTime.Now}]: Exception occurred. Message: '{message}'. Exception Details:{Environment.NewLine}{exception}"; - logger.LogError(logMessage); - } - - public override void Info(string message) { - logger.LogInformation(message); - } - } -} diff --git a/AspNetCore.Reporting.MVC/appsettings.json b/AspNetCore.Reporting.MVC/appsettings.json index a611470..1cf7a75 100644 --- a/AspNetCore.Reporting.MVC/appsettings.json +++ b/AspNetCore.Reporting.MVC/appsettings.json @@ -8,6 +8,7 @@ "Logging": { "LogLevel": { "Default": "Information", + "DevExpress": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } diff --git a/Readme.md b/Readme.md index 2d322e4..405a0b4 100644 --- a/Readme.md +++ b/Readme.md @@ -427,37 +427,21 @@ This document section describes the best practices that you should follow when y ### Log Errors that Occurred in the Code of DevExpress Reporting Components -To handle exceptions generated by DevExpress reporting components, implement and register a logger service and override the `Error` method in your service implementation. In the `Error` method's implementation, save errors to a log or database. If a Visual Studio debugger is attached, you can set a breakpoint and inspect errors in the Watch window. +DevExpress reporting components write log messages through the standard [Microsoft.Extensions.Logging](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/logging/) API. Messages go to the logging providers registered in the application, so no custom logger class is required. To save errors to a file or database, register a logging provider that writes to that storage. -##### Implement a Logger Class +Use the `DevExpress` log category to configure which messages are logged. The following *appsettings.json* configuration logs DevExpress messages with the `Information` level and higher: -[ReportingLoggerService.cs](AspNetCore.Reporting.Common/Services/Reporting/ReportingLoggerService.cs): - -```csharp -public class ReportingLoggerService: LoggerService { - readonly ILogger logger; - public ReportingLoggerService(ILogger logger) { - this.logger = logger; - } - public override void Error(Exception exception, string message) { - var logMessage = $"[{DateTime.Now}]: Exception occurred. Message: '{message}'. Exception Details:{Environment.NewLine}{exception}"; - logger.LogError(logMessage); - } - - public override void Info(string message) { - logger.LogInformation(message); - } +```json +"Logging": { + "LogLevel": { + "Default": "Information", + "DevExpress": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } } ``` -##### Register the Logger - -Call `LoggerService.Initialize` at application startup and pass the logger factory obtained from the DI container: - -```cs -LoggerService.Initialize(new ReportingLoggerService(loggerFactory.CreateLogger("DXReporting"))); -``` - ### Use Custom Exception Handlers Use custom exception handler services to customize error details that are passed to the client and displayed in the client UI: