public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { var message = formatter(state, exception); var source = $"{_categoryName}"; EventBuilder eventBuilder = null; if (exception != null) { eventBuilder = ExceptionlessClient.Default.CreateException(exception); } else { eventBuilder = ExceptionlessClient.Default.CreateLog(source, message, logLevel.ToString()); } eventBuilder.SetMessage(message).SetSource(source); if (eventId != 0) { eventBuilder.SetProperty("enentId", eventId); } eventBuilder.Submit(); }
/// <summary> /// 设置异常数据 /// </summary> /// <param name="builder">事件生成器</param> /// <param name="content">日志内容</param> private void SetExceptionData(EventBuilder builder, ILogContent content) { if (content?.Exception?.Data != null && content.Exception.Data.Count == 0) { return; } builder.SetProperty("异常数据", content?.Exception?.Data); }
/// <summary> /// 设置跟踪号 /// </summary> /// <param name="builder">事件生成器</param> /// <param name="content">日志内容</param> private void SetReferenceId(EventBuilder builder, ILogContent content) { if (!IsValidIdentifier(content.LogId)) { builder.SetProperty("ReferenceIdException", content.LogId); return; } builder.SetReferenceId($"{content.LogId}"); }
/// <summary> /// 添加属性集合 /// </summary> /// <param name="builder">事件生成器</param> /// <param name="content">日志转换器</param> private void AddProperties(EventBuilder builder, ILogConvert content) { if (content == null) return; foreach (var parameter in content.To().OrderBy(t => t.SortId)) { if (string.IsNullOrWhiteSpace(parameter.Value.SafeString())) continue; builder.SetProperty($"{GetLine()}. {parameter.Text}", parameter.Value); } }
/// <summary> /// 添加扩展属性集合 /// </summary> /// <param name="builder">事件生成器</param> /// <param name="content">日志转换器</param> private void AddExtraProperties(EventBuilder builder, ILogContent content) { if (content == null) { return; } foreach (var parameter in content.ExtraProperties) { if (string.IsNullOrWhiteSpace(parameter.Value.SafeString())) { continue; } builder.SetProperty(parameter.Key, parameter.Value); } }
private static void Submit(EventBuilder builder, string[] tags, List <KeyValuePair <string, object> > propertys) { if (tags != null) { builder.AddTags(tags); } if (propertys != null) { foreach (var property in propertys) { builder.SetProperty(property.Key, property.Value); } } builder.Submit(); }