예제 #1
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     if (Provider == null)
     {
         return;
     }
     try
     {
         using (var p = Provider.CreateScope())
         {
             var acc = p.ServiceProvider.GetService <IHttpContextAccessor>();
             if (acc != null)
             {
                 var httpContext = acc.HttpContext;
                 if (httpContext != null && httpContext.Items.ContainsKey(TenantServices.TenantFinderService.HttpContextTenantIdKey))
                 {
                     int tenantId = (int)httpContext.Items[TenantServices.TenantFinderService.HttpContextTenantIdKey];
                     logEvent.AddPropertyValueIfAbsent(propertyFactory, TenantIdPropertyName, tenantId);
                     var principal = httpContext.User;
                     if (principal != null && principal.Identity != null && principal.Identity.Name != null)
                     {
                         logEvent.AddPropertyValueIfAbsent(propertyFactory, PrincipalNamePropertyName, principal.Identity.Name);
                     }
                 }
             }
         }
     }
     catch (Exception)
     { }
 }