protected override Task DoInsert(LogInsert model, BaseLogInformation info, int maxLength) { var subject = $"[{model.Identifier}] Log Insert for: {model.Application ?? "Unknown"} ({Host.EnvironmentName})"; var body = $@" {info.ApplicationStr} Environment: {Host.EnvironmentName} {info.MachineStr} {info.TypeStr} {info.IdentifierStr} {info.TimestampStr} {info.SeverityStr} {info.RequestStr} {info.OrderStr} {info.SessionStr()} {info.UserStr} {info.MessageStr.ShortenWithEllipses(maxLength)} {info.CategoryStr.ShortenWithEllipses(maxLength)} {string.Join("\r\n", model.Other)} "; return(Email.SendAsync(EmailImpl, EmailType.Logging, subject, body)); }
public virtual void Generic(BaseLogInformation info, Action errorAction = null) { if (EnabledPreCheck(info)) { DoLog(info, errorAction); } }
protected void DoLog(BaseLogInformation info, Action errorAction = null) { _ = SafeTry.EmailException( EmailImpl, App, async() => { // Set properties on the object (ones that aren't set on the constructor that may take a bit) info.SetProperties(Config); // Log it (Insert) await DoAllLoggerInserts(info, errorAction); // Waited for complete above so that this can be set (free it up for updates) if (info is TimerBaseInformation timer) { timer.SetComplete = true; } }
protected virtual LogInsert ToInsertModel(BaseLogInformation info, int maxLength) { var model = new LogInsert { Type = info.Type, Identifier = info.Identifier, Timestamp = info.Timestamp, Severity = info.Severity, Order = info.Order, RequestId = info.RequestId, Session = info.Session, UserId = info.UserId ?? 0, Message = info.Message.ShortenWithEllipses(maxLength), Category = info.Category.ShortenWithEllipses(maxLength), Machine = info.Machine, Application = info.Application }; if (IncludeIdentity) { foreach (var(key, value) in info.IdentityProperties) { model.Other.Add(key, value.ShortenWithEllipses(maxLength)); } } if (IncludeStatic) { foreach (var(key, value) in info.StaticProperties) { model.Other.Add(key, value.ShortenWithEllipses(maxLength)); } } if (IncludeHigh) { foreach (var(key, value) in info.HighProperties) { model.Other.Add(key, value.ShortenWithEllipses(maxLength)); } } if (IncludeMed) { foreach (var(key, value) in info.MedProperties) { model.Other.Add(key, value.ShortenWithEllipses(maxLength)); } } // ReSharper disable once InvertIf if (IncludeLow) { foreach (var(key, value) in info.LowProperties) { model.Other.Add(key, value.ShortenWithEllipses(maxLength)); } } return(model); }
/// <summary> /// Actual implementation of logging the record /// </summary> /// <param name="model">The model containing everything to be logged</param> /// <param name="info">The log information class</param> /// <param name="maxLength">When to truncate items</param> protected abstract Task DoInsert(LogInsert model, BaseLogInformation info, int maxLength);
/// <summary> /// Called by the logger, this is when a record needs to be logged /// </summary> /// <remarks>Do not override this one - you should instead customize in DoInsert</remarks> /// <param name="info">The log information class</param> /// <param name="maxLength">When to truncate items</param> public virtual Task Insert(BaseLogInformation info, int maxLength) => DoInsert(ToInsertModel(info, maxLength), info, maxLength);
private string GetEmailSubjectPrefix(BaseLogInformation info) { return($"{System.Environment.MachineName} ({App.Environment}): {App.Name}; "); }
private bool EnabledPreCheck(BaseLogInformation info) => info != null && Config.Enabled && Config.TypeEnabled(info.Type);
protected override Task DoInsert(LogInsert model, BaseLogInformation info, int maxLength) { Debug.WriteLine(model.Message, info.CategoryStr); WriteOther(model.Other); return(Task.CompletedTask); }
public void Generic(BaseLogInformation info, Action errorAction = null) { }