/// <summary> /// Converts the specified event to string. /// </summary> /// <param name="ev">The event to consider.</param> /// <returns>The string corresponding to the specified event using the specified formater.</returns> public static string ToString <T>(this IBdoLogEvent ev) where T : IBdoLoggerFormat, new() { var formater = new T(); return(formater.ToString(ev)); }
/// <summary> /// /// </summary> /// <typeparam name="ev"></typeparam> public string ToString(IBdoLogEvent ev) { if (ev != null) { int level = ev.Level; string indent = new string(' ', (level < 0 ? 0 : level - 1) * 2); return(indent + (ev.Log != null ? "o " : "- ") + ev.DisplayName + (!string.IsNullOrEmpty(ev.Description) ? " | " + ev.Description : "")); } return(null); }
/// <summary> /// Converts the specified log to the Api log DTO. /// </summary> /// <param name="ev">The log to consider.</param> /// <param name="key">The key to consider.</param> /// <param name="alternateKey">The alternate key to consider.</param> /// <returns>Returns the Api log DTO.</returns> public static BdoApiLogEventDto ToApiDto(this IBdoLogEvent ev, string key = "*", string alternateKey = null) { return(ev == null ? null : new BdoApiLogEventDto() { CreationDate = ev.CreationDate, Criticality = ev.Criticality, Date = ev.Date, Description = ev.Description, DisplayName = ev.DisplayName, Id = ev.Id, Kind = ev.Kind, LastModificationDate = ev.LastModificationDate, Name = ev.Name, ResultCode = ev.ResultCode }); }
/// <summary> /// /// </summary> /// <typeparam name="ev"></typeparam> public void Log(IBdoLogEvent ev) { if (ev != null && _nativeLogger != null) { string st = _formater?.ToString(ev); switch (ev?.Kind ?? Events.EventKinds.None) { case Events.EventKinds.Checkpoint: _nativeLogger.LogTrace(st); break; case Events.EventKinds.Error: _nativeLogger.LogError(st); break; case Events.EventKinds.Exception: _nativeLogger.LogCritical(st); break; case Events.EventKinds.Message: _nativeLogger.LogInformation(st); break; case Events.EventKinds.Warning: _nativeLogger.LogWarning(st); break; } if (ev?.Log != null) { foreach (IBdoLogEvent logEvent in ev.Log.Events) { Log(logEvent); } } } }