Registro de errores simple y conveniente para sitios en .NET Core

Quizás, muchos están familiarizados con la biblioteca ELMAH (Módulos y controladores de registro de errores) , que le permite organizar un registro de errores simple para cualquier sitio creado con .NET Framework.













Esta herramienta simple y probada me ha ayudado en muchos proyectos.

Hace varios años, mientras creaba mi nuevo proyecto para .NET Core, me molestó descubrir que ELMAH no funciona en .NET Core.







opensource ! , ELMAH .NET Core.







, , pet-. , , «» ElmahCore.







, ElmahCore – opensource , , .NET Core.

, , :







  • ,
  • HTTP : (header), , cookies,


, Microsoft.Extensions.Logging (ILogger) HTTP .

:







  • XML
  • , MSSQL, MySQL, PostgreSQL


:







  1. nuget- elmahcore.
  2. Startup.cs:


services.AddElmah(); //   ConfigureServices 
app.UseElmah(); //    Configure
      
      





.

, , ~/elmah.

UI, VUE.js













, . :







services.AddElmah(options =>
{
   options.SourcePaths = new []
   {
      @"D:\tmp\ElmahCore.DemoCore3",
      @"D:\tmp\ElmahCore.Mvc",
      @"D:\tmp\ElmahCore"
   };
});

      
      





«Log» Microsoft.Extensions.Logging HTTP .













, !

, :







services.AddElmah(options =>
{
        options.OnPermissionCheck = context => context.User.Identity.IsAuthenticated;
});
      
      





UseElmah, UseAuthentication UseAuthorization







app.UseAuthentication();
app.UseAuthorization();
app.UseElmah();
      
      





Puede filtrar los errores registrados utilizando filtros implementados en el código (implementando la interfaz IErrorFilter) o en el archivo de configuración xml ( https://elmah.github.io/a/error-filtering/examples/ ).







services.AddElmah<XmlFileErrorLog>(options =>
{
    options.FiltersConfig = "elmah.xml";
    options.Filters.Add(new MyFilter());
})
      
      





Además de registrar el registro de errores, la biblioteca le permite organizar la distribución de notificaciones (a través de la implementación de IErrorNotifier), por ejemplo, por correo electrónico.







services.AddElmah<XmlFileErrorLog>(options =>
{
    options.Notifiers.Add(new ErrorMailNotifier("Email",emailOptions));
});
      
      





Espero que esta biblioteca gratuita sea útil en sus proyectos.

Puede encontrar más información sobre la biblioteca aquí .








All Articles