コード例 #1
0
        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));
        }
コード例 #2
0
 public virtual void Generic(BaseLogInformation info, Action errorAction = null)
 {
     if (EnabledPreCheck(info))
     {
         DoLog(info, errorAction);
     }
 }
コード例 #3
0
        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;
                }
            }
コード例 #4
0
ファイル: BaseLogger.cs プロジェクト: dbartels13/Common
        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);
        }
コード例 #5
0
ファイル: BaseLogger.cs プロジェクト: dbartels13/Common
 /// <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);
コード例 #6
0
ファイル: BaseLogger.cs プロジェクト: dbartels13/Common
 /// <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);
コード例 #7
0
 private string GetEmailSubjectPrefix(BaseLogInformation info)
 {
     return($"{System.Environment.MachineName} ({App.Environment}): {App.Name}; ");
 }
コード例 #8
0
 private bool EnabledPreCheck(BaseLogInformation info)
 => info != null && Config.Enabled && Config.TypeEnabled(info.Type);
コード例 #9
0
ファイル: DebugLogger.cs プロジェクト: dbartels13/Common
 protected override Task DoInsert(LogInsert model, BaseLogInformation info, int maxLength)
 {
     Debug.WriteLine(model.Message, info.CategoryStr);
     WriteOther(model.Other);
     return(Task.CompletedTask);
 }
コード例 #10
0
ファイル: NonLogger.cs プロジェクト: dbartels13/Common
 public void Generic(BaseLogInformation info, Action errorAction = null)
 {
 }