Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

TenantId on logfile with log4net #8107


User avatar
0
sanliotrade created

Is there a way to add the TenantId on log pattern?

Log4net has custom properties, but where to set the custom property on asp.net zero? (.net core + angular)

log4net.ThreadContext.Properties[ "tenantId" ] = _abpSession.TenantId;


2 Answer(s)
  • User Avatar
    1
    maliming created
    Support Team

    Can use asp net core middleware.

    <conversionPattern value="%property{tenantid} %-5level %date [%-5.5thread] %-40.40logger - %message%newline" />
    
    app.UseAbp(); // Initializes ABP framework.
    
    app.Use(async (context, next) =>
    {
        log4net.ThreadContext.Properties["tenantid"] =
            context.RequestServices.GetRequiredService<IAbpSession>().TenantId.ToString();
    
        await next.Invoke();
    });
    
    
    1 INFO  2019-11-28 13:26:43,808 [9    ] Microsoft.AspNetCore.Hosting.Diagnostics - Request finished in 80.043ms 200 application/x-javascript
    
  • User Avatar
    0
    sanliotrade created

    Thank you!!