Silky Microservice FrameworkSilky Microservice Framework
Home
Docs
Config
Source
github
gitee
  • 简体中文
  • English
Home
Docs
Config
Source
github
gitee
  • 简体中文
  • English
  • Introduction

    • Silky Framework Overview
  • Getting Started

    • Glossary
    • Quick Start
    • Project Template
    • Microservice Architecture
    • Sample Projects
  • Host & Module

    • Host Types
    • Gateway Configuration
    • Module System
    • Plugin System
  • Gateway & HTTP

    • Swagger / OpenAPI
    • MiniProfiler
    • CORS
    • Audit Logging
  • Service & RPC

    • App Services & Service Entries
    • RPC Communication
    • WebSocket
    • Service Registry
    • Service Governance
  • Data & Cache

    • EFCore Data Access
    • Caching
    • Distributed Lock
  • Security & Auth

    • Identity & Authentication
    • Distributed Transactions
  • Infrastructure

    • Dependency Injection
    • Object Mapping
    • Validation
    • Link Tracking (SkyAPM)
    • Logging (Serilog)
    • Health Checks
    • Message Bus (MassTransit)
    • Unit & Integration Testing

Overview

Silky's Silky.Http.Auditing package provides automatic audit logging for HTTP requests through the gateway. It captures request/response metadata, user identity, timing, and result codes — making it straightforward to track who did what and when.

Installation

<PackageReference Include="Silky.Http.Auditing" Version="3.9.2" />

Setup

Module

[DependsOn(
    typeof(HttpAuditingModule),
    typeof(GatewayHostModule)
)]
public class GatewayModule : SilkyModule { }

Startup.cs

public void ConfigureServices(IServiceCollection services)
{
    services.AddSilkyHttpCore()
            .AddAuditing();
}

public void Configure(IApplicationBuilder app)
{
    app.UseAuthentication();
    app.UseAuthorization();
    app.UseAuditing();     // place after authentication so user info is available
    app.UseSilkyRpcProxy();
}

Audit Log Content

Each audit log entry captures:

FieldDescription
UserIdAuthenticated user ID (from JWT claim)
UserNameUser display name
TenantIdTenant ID (multi-tenant scenarios)
ClientIpClient IP address
HttpMethodGET / POST / PUT / DELETE
UrlRequest URL
ParametersSerialized request body/query
ExecutionTimeRequest start timestamp
ExecutionDurationDuration in milliseconds
HttpStatusCodeHTTP response status code
ExceptionException details if the request failed

Storing Audit Logs

Implement IAuditingStore to persist audit logs to your storage backend:

public class DatabaseAuditingStore : IAuditingStore, IScopedDependency
{
    private readonly IRepository<AuditLog> _repository;

    public DatabaseAuditingStore(IRepository<AuditLog> repository)
    {
        _repository = repository;
    }

    public async Task SaveAsync(AuditLogInfo auditLogInfo)
    {
        var log = new AuditLog
        {
            UserId       = auditLogInfo.UserId,
            UserName     = auditLogInfo.UserName,
            HttpMethod   = auditLogInfo.HttpMethod,
            Url          = auditLogInfo.Url,
            ClientIp     = auditLogInfo.ClientIp,
            Duration     = auditLogInfo.ExecutionDuration,
            StatusCode   = auditLogInfo.HttpStatusCode,
            CreatedAt    = auditLogInfo.ExecutionTime
        };
        await _repository.InsertAsync(log);
    }
}

Configuration

{
  "auditing": {
    "isEnabled": true,
    "isEnabledForAnonymousUsers": false,
    "isEnabledForGetRequests": false,
    "ignoredUrls": [
      "/health",
      "/swagger"
    ]
  }
}
OptionDefaultDescription
isEnabledtrueEnable/disable audit logging
isEnabledForAnonymousUsersfalseLog unauthenticated requests
isEnabledForGetRequestsfalseLog read-only GET requests
ignoredUrls[]URL patterns excluded from auditing
Edit this page
Prev
CORS