Segugio 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Segugio --version 1.0.0
                    
NuGet\Install-Package Segugio -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Segugio" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Segugio" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Segugio" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Segugio --version 1.0.0
                    
#r "nuget: Segugio, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Segugio@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Segugio&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Segugio&version=1.0.0
                    
Install as a Cake Tool

Segugio

Segugio è una libreria per la gestione del sistema di audit in progetti .NET. Consente di configurare facilmente provider di audit e raccogliere informazioni di log dettagliate: indirizzi IP, sessioni, route HTTP, e molto altro. La libreria supporta un'architettura flessibile e altamente estendibile.


Caratteristiche

  • Modulare: Configura facilmente diversi provider di audit.
  • Flessibile: Supporta audit per database, Serilog, file di log, ecc.
  • Integrabile: Pensato per essere incluso in qualsiasi progetto .NET.
  • Personalizzabile: Pienamente estendibile per adattarsi a qualsiasi esigenza di logging.

Installazione

1. Aggiungere la libreria via NuGet

Puoi installare Segugio direttamente dal Package Manager Console usando il comando:

Install-Package Segugio

Oppure aggiungendolo nel file .csproj:

<PackageReference Include="Segugio" Version="1.0.0" />

2. Usare la DLL

Se preferisci utilizzare il file DLL precompilato:

  1. Copia il file Segugio.dll nella directory desiderata del tuo progetto.
  2. Aggiungi un riferimento alla DLL:
    • In Visual Studio, fai clic con il tasto destro sul tuo progetto > Add Reference > Browse > seleziona il file Segugio.dll.

Configurazione

Passaggi principali

  1. Implementa l'interfaccia IContestoAudit per configurare informazioni contestuali (indirizzo IP, ID sessione, dati di routing).
  2. Implementa l'interfaccia IUtenteAudit per fornire informazioni sull'utente (es. ID utente, ruolo).
  3. Usa uno dei provider già inclusi nella libreria.
  4. Crea uno o più provider derivando dall'interfaccia ISegugioProvider per salvare i dati audit nel supporto desiderato.

Esempio di utilizzo

1. Creazione del contesto di audit

public class ContestoAudit : IContestoAudit
{
    public string GetRemoteIpAddress() => "192.168.1.1"; // Esempio di indirizzo IP remoto

    public string GetSessionId() => Guid.NewGuid().ToString(); // Genera un ID univoco per la sessione

    public string GetTerminalId() => Environment.MachineName; // Restituisce il nome del terminale

    public RouteData? GetHttpRouteData() => return new RouteData(); // Restituisci configurazione per la rotta HTTP (esempio semplificato)
}

2. Uso di un provider già incluso nella libreria

Ad esempio, puoi configurare i due già previsti così:

    new SqlServerProvider(
        new AuditTableConfiguration(connectionString,"SchemaTabellaDiAudit","NomeTabellaDiAudit",
            "CampoUserName","CampoDatiJSon", "CampoUltimoAggiornamento", 
            "CampoProfilo", "CampoUtenteAmministratore", 
            "CampoIdTabellaAudit", "CampoIndirizzoIp","CampoRouteDataJson"
        )
    ),
    new SerilogProvider("serverSerilog", "porta")

3. Creazione di un nuovo provider

Ad esempio, creare un nuovo provider per Serilog così:

public class SerilogProvider : ISegugioProvider
{
    public string ServerAddress { get; set; } = "127.0.0.1";
    public string ServerPort { get; set; } = "514";

    public AuditDataProvider GetAuditProvider(IContestoAudit contesto, IUtenteAudit utente)
    {
        var serilogProvider = new DynamicDataProvider(config =>
        {
            config.OnInsert(ev =>
            {
                var logger = new LoggerConfiguration()
                    .WriteTo.TCPSink($"tcp://{ServerAddress}:{ServerPort}")
                    .CreateLogger();

                logger.Information($"Log {ev.EventType}");
            });
        });
        return serilogProvider;
    }
}

4. Setup del sistema di audit

Connetti tutto alla classe SegugioAuditor e configura il sistema:

var contestoAudit = new ContestoAudit();
var utenteAudit = new UtenteAudit();

var providers = new List<ISegugioProvider>
{
    new SerilogProvider("127.0.0.1", "514") // Configura il provider
};

var auditor = new SegugioAuditor(contestoAudit, utenteAudit);
auditor.Setup(providers);

// Sistema audit configurato!

5. Creazione dei log di audit

Ora puoi utilizzare il sistema di audit per registrare le attività:

using AuditScope = Audit.Core.AuditScope;

public void OperazioneEsempio()
{
    using (var scope = AuditScope.Create("Operazione", () => new { Data = "Esempio" }, new { Utente = "Admin" }))
    {
        // Logica della tua operazione
    }
}

Estendibilità

  • Aggiungere nuovi provider: Implementa l'interfaccia ISegugioProvider per supportare altri mezzi di logging (es. MongoDB, ElasticSearch).
  • Contesto personalizzato: Adatta la tua implementazione di IContestoAudit e IUtenteAudit per aggiungere altre informazioni come dati del server o informazioni client-specifiche.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.6 258 9/21/2025
1.0.5 620 8/19/2025
1.0.4 175 8/19/2025
1.0.3 222 7/9/2025
1.0.2 218 6/4/2025
1.0.1 215 5/25/2025
1.0.0 221 5/20/2025