public void Emit(LogEvent logEvent) { if (logEvent == null || !_client.Configuration.IsValid) { return; } var minLogLevel = _client.Configuration.Settings.GetMinLogLevel(logEvent.GetSource()); if (logEvent.GetLevel() < minLogLevel) { return; } var builder = _client.CreateFromLogEvent(logEvent); if (_includeProperties && logEvent.Properties != null) { foreach (var property in logEvent.Properties) { if (property.Key != Constants.SourceContextPropertyName) { builder.SetProperty(property.Key, property.Value.FlattenProperties()); } } } _additionalOperation?.Invoke(builder); builder.Submit(); }
protected override void Write(LogEventInfo logEvent) { if (!_client.Configuration.IsValid) { return; } LogLevel minLogLevel = LogLevel.FromOrdinal(_client.Configuration.Settings.GetMinLogLevel(logEvent.LoggerName).Ordinal); if (logEvent.Level < minLogLevel) { return; } var builder = _client.CreateFromLogEvent(logEvent); foreach (var field in Fields) { var renderedField = field.Layout.Render(logEvent); if (!String.IsNullOrWhiteSpace(renderedField)) { builder.AddObject(renderedField, field.Name); } } builder.Submit(); }
protected override void Write(AsyncLogEventInfo info) { var builder = _client.CreateFromLogEvent(info.LogEvent); foreach (var field in Fields) { var renderedField = field.Layout.Render(info.LogEvent); if (!String.IsNullOrWhiteSpace(renderedField)) { builder.AddObject(renderedField, field.Name); } } builder.Submit(); }
public void Emit(LogEvent logEvent) { if (logEvent == null || !_client.Configuration.IsValid) { return; } var builder = _client.CreateFromLogEvent(logEvent); if (_includeProperties && logEvent.Properties != null) { foreach (var property in logEvent.Properties) { builder.SetProperty(property.Key, FlattenProperties(property.Value)); } } if (_additionalOperation != null) { _additionalOperation(builder); } builder.Submit(); }
/// <summary>提交.</summary> /// <param name="logEvent">日志事件</param> public void Emit(LogEvent logEvent) { if (logEvent == null || !_client.Configuration.IsValid) { return; } var minLogLevel = _client.Configuration.Settings.GetMinLogLevel(logEvent.GetSource()); if (LogLevelSwitcher.Switch(logEvent.Level) < minLogLevel) { return; } var builder = _client .CreateFromLogEvent(logEvent) .AddTags(_defaultTags); if (_includeProperties && logEvent.Properties != null) { foreach (var property in logEvent.Properties) { switch (property.Key) { case Constants.SourceContextPropertyName: continue; case Event.KnownDataKeys.UserInfo when property.Value is StructureValue uis && string.Equals(nameof(UserInfo), uis.TypeTag): var userInfo = uis.FlattenProperties() as Dictionary <string, object>; if (userInfo is null) { continue; } // 忽略数据属性 var identity = userInfo[nameof(UserInfo.Identity)] as string; var name = userInfo[nameof(UserInfo.Name)] as string; if (!string.IsNullOrWhiteSpace(identity) || !string.IsNullOrWhiteSpace(name)) { builder.SetUserIdentity(identity, name); } break; case Event.KnownDataKeys.UserDescription when property.Value is StructureValue uds && string.Equals(nameof(UserDescription), uds.TypeTag): var userDescription = uds.FlattenProperties() as Dictionary <string, object>; if (userDescription is null) { continue; } // 忽略数据属性 var emailAddress = userDescription[nameof(UserDescription.EmailAddress)] as string; var description = userDescription[nameof(UserDescription.Description)] as string; if (!string.IsNullOrWhiteSpace(emailAddress) || !string.IsNullOrWhiteSpace(description)) { builder.SetUserDescription(emailAddress, description); } break; default: builder.SetProperty(property.Key, property.Value.FlattenProperties()); break; } } } _additionalOperation?.Invoke(builder); builder.Submit(); }