npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ngx-registri-log

v0.10.4

Published

Small Angular/.Net Core library that offers functions of:

Downloads

4

Readme

Registri Log

Small Angular/.Net Core library that offers functions of:

  • EF Core Audit
  • API Request/Response logging
  • Serilog additional functions
  • Angular GUI of all functions

If the documentation or the project should present problems you can open an issue indicating the problem:)

Link:

How To: install and configure

MS .Net Core

  • Install the net-logs-log package from nuget.org --> Link

    dotnet add package net-registri-log
  • Configure the library options in the appsettings. {Env} .json file:

      "net-registri-log": {
        "ApiLog.Options": {
          "Enable": true,
          "TrackRequestBody": true,
          "TrackResponseBody": true,
          "IgnorePath": [
            "/ApiLog/"
          ]
        },
        "Logs.Options": {
          "Enable": true,
          "SerilogDebuggingSelfLogEnable": true,
          "SerilogSelfFileName": "SerilogSelf.log"
        }
      },
      
  • Add to the ConfigureServices method:

    public void ConfigureServices(IServiceCollection services)
    {
        // ...
        // ...
          
        services.AddNetRegistriLog(Configuration);
      
        // ricordati di configurare il tuo DbContext!!!
        services.AddDbContext<ApplicationDbContext>(options =>
                                                    {                                              options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
                                                    });
        // ...
        // ...
    }
  • Add to the Configure method:

    public void ConfigureServices(IServiceCollection services)
    {
        app.UseNetRegistriLog();
          
        // ...
        // ...
    }
  • Update the Program class:

        public class Program
        {
            public static void Main(string[] args)
            {
                // required to configure the Serilog
                net_registri_log.Logs.Logger.Initialize();
      
                try
                {
                    Log.Information("Starting host...");
                    CreateHostBuilder(args).Build().Run();
                }
                catch (Exception ex)
                {
                    Log.Fatal(ex, "Host terminated unexpectedly.");
                }
                finally
                {
                    Log.CloseAndFlush();
                }
            }
      
            public static IHostBuilder CreateHostBuilder(string[] args) =>
                Host.CreateDefaultBuilder(args)
                    .UseSerilog()	// needed for Serilog
                    .ConfigureWebHostDefaults(webBuilder =>
                    {
                        webBuilder.UseStartup<Startup>();
                    });
        }
      
  • Add the Serilog configuration to the appsettings.{Env}.json file. The library uses a precise configuration. Change or extend the example:

      "Serilog": {
        "Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File", "Serilog.Sinks.MSSqlServer", "Serilog.Expressions" ],
        "MinimumLevel": {
          "Default": "Debug",
          // the namespaces of the Override section ignore the Default MinimumLevel.
          "Override": {
            "Microsoft": "Warning",
            "Microsoft.Hosting.Lifetime": "Information",
            "System": "Warning",
            "Microsoft.EntityFrameworkCore.Database.Command": "Warning",
            "Microsoft.AspNetCore.Authentication": "Debug",
            "net-registri-log": "Debug"
          }
        },
        "WriteTo": [
          {
            "Name": "Logger",
            "Args": {
              "configureLogger": {
                // all logging service providers (sinks) are defined here.
                "WriteTo": [
                  // log settings to console.
                  // https://github.com/serilog/serilog-sinks-console
                  {
                    "Name": "Console",
                    "Args": {
                      "outputTemplate": "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{Data:l}{NewLine}{Exception}{NewLine}",
                      "theme": "Serilog.Sinks.SystemConsole.Themes.AnsiConsoleTheme::Code, Serilog.Sinks.Console"
                    }
                  },
                  // log settings to file.
                  // https://github.com/serilog/serilog-sinks-file
                  {
                    // name of the sink type.
                    "Name": "File",
                    "Args": {
                      // directory/path where the logs will be written.
                      "path": "../LogFiles/net-registri-log.webapi/net-registri-log.log",
                      // maximum size of single log file.
                      "fileSizeLimitBytes": 1000000,
                      // (setting 3, for more info see Serilog documentation)
                      "rollingInterval": 3,
                      "rollOnFileSizeLimit": true,
                      "shared": true,
                      "outputTemplate": "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{Data:l}{NewLine}{Exception}{NewLine}",
                      // disk write interval
                      "flushToDiskInterval": 1
                    }
                  },
                  // log settings on sql server.
                  // https://github.com/serilog/serilog-sinks-mssqlserver
                  {
                    // nome del tipo di sink.
                    "Name": "MSSqlServer",
                    "Args": {
                      "connectionString": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=net-registri-log;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False",
                      // table on which the logger will write.
                      // IT CAN BE CHANGED AS NEEDED
                      "sinkOptionsSection": {
                        "tableName": "Logs",
                        "schemaName": "dbo",
                        // if true Serilog will create the necessary tables and fields.
                        "autoCreateSqlTable": true
                      },
                      "columnOptionsSection": {
                        // some unnecessary standard columns of the logging service have been removed.
                        // IT CAN BE CHANGED AS NEEDED
                        "removeStandardColumns": [ "MessageTemplate", "Properties" ],
                        // HERE ARE DEFINED THE CUSTOMIZED FIELDS OF THE LIBRARY.
                        // !!! YOU CAN ADD THE OTHER FIELDS BUT DO NOT REMOVE ANY CONFIGURATION !!!
                        "customColumns": [
                          {
                            "ColumnName": "UserName",
                            "DataType": "nvarchar",
                            "DataLength": 50,
                            "AllowNull": true
                          },
                          {
                            "ColumnName": "Operation",
                            "DataType": "nvarchar",
                            "DataLength": 50,
                            "AllowNull": true
                          },
                          {
                            "ColumnName": "JsonObject",
                            "DataType": "nvarchar",
                            "AllowNull": true
                          }
                        ],
                        "timeStamp": {
                          "columnName": "Timestamp",
                          "convertToUtc": false
                        }
                      }
                    }
                  }
                ]
              }
            }
          }
        ],
        "Enrich": [ "FromLogContext" ]
      }
      
  • The necessary library migrations are automatically applied when the project is first started. For more information check out the static UpdateDatabaseMigrate method in the net_registri_log.Providers.ApplicationBuilderExtensions class.

NB: from now on, to update the context of your project it will be necessary to specify:

Add-Migration <nome> -Context <context>

API-Log

The function will be active from the first start. The information is contained in the dbo.ApiLogs table of the configured database.

Audit-Log

To use this feature you need to use a workaround:

  • Use the DI to get the RegistriLogDbContext context.

  • Instead of using the SaveChanges SaveChangesAsync of your context use the context of the library by passing it the context you were working on:

    await _registriLogDbContext.SaveAndAuditChangesAsync(_context);
  • The information is contained in the dbo.AuditLogs table of the configured database.

Logs

The library extends some functionality of the Serilog library:

  • API for consulting logs
  • extension methods that handle two new data: jsonObject, operation

NB: Serilog must be configured (see above).

Angular Project

  • Install the package via npm --> Link

    npm i ngx-registri-log
  • Add the module to the project in app.module.ts.

    import { NgxRegistriLogModule } from 'ngx-registri-log';
      
    @NgModule({
      // ...
      // ...
        
      imports: [
        NgxRegistriLogModule
      ],
        
      // ...
      // ...
    })
    export class AppModule { }
  • The library exposes the components:

    <lib-audit-log></lib-audit-log>
    <lib-event-api></lib-event-api>
    <lib-logs></lib-logs>

Sample and Development Projects

The following projects have been developed in the repository:

  • node\ --> workspace Angular
    • node\projects\ngx-logs-logs --> library project
    • node\projects\client --> library test client
  • net\ --> .Net Core solution
    • net\net-registri-logs --> library project
    • net\net-registri-log.webapi --> test API project (for tests I recommend using swagger UI)
  • sample\ --> example .Net + Angular stack with libraries configured by NPM and NuGet.