Пример #1
0
        /// <summary>
        /// Creates the message.
        /// </summary>
        /// <param name="logEvent">The log event.</param>
        /// <returns>A message card.</returns>
        private MicrosoftTeamsMessageCard CreateMessage(ExtendedLogEvent logEvent)
        {
            var renderedMessage = logEvent.LogEvent.RenderMessage(this.options.FormatProvider);

            var request = new MicrosoftTeamsMessageCard
            {
                Title    = this.options.Title,
                Text     = renderedMessage,
                Color    = GetAttachmentColor(logEvent.LogEvent.Level),
                Sections = this.options.OmitPropertiesSection ? null : new[]
                {
                    new MicrosoftTeamsMessageSection
                    {
                        Title = "Properties",
                        Facts = this.GetFacts(logEvent).ToArray()
                    }
                },
                PotentialActions = null
            };

            // Add static URL button(s) from options
            if (this.options.Buttons.Any())
            {
                request.PotentialActions = new List <MicrosoftTeamsMessageAction>();
                this.options.Buttons.ToList().ForEach(btn => request.PotentialActions.Add(new MicrosoftTeamsMessageAction("OpenUri", btn.Name, new MicrosoftTeamsMessageActionTargetUri(btn.Uri))));
            }

            return(request);
        }
        /// <summary>
        /// Gets the facts.
        /// </summary>
        /// <param name="logEvent">The log event.</param>
        /// <returns>A list of facts.</returns>
        private IEnumerable <MicrosoftTeamsMessageFact> GetFacts(ExtendedLogEvent logEvent)
        {
            yield return(new MicrosoftTeamsMessageFact
            {
                Name = "Level",
                Value = logEvent.LogEvent.Level.ToString()
            });

            yield return(new MicrosoftTeamsMessageFact
            {
                Name = "MessageTemplate",
                Value = logEvent.LogEvent.MessageTemplate.Text
            });

            if (logEvent.LogEvent.Exception != null)
            {
                yield return(new MicrosoftTeamsMessageFact {
                    Name = "Exception", Value = logEvent.LogEvent.Exception.ToString()
                });
            }

            foreach (var property in logEvent.LogEvent.Properties)
            {
                yield return(new MicrosoftTeamsMessageFact
                {
                    Name = property.Key,
                    Value = property.Value.ToString(null, _options.FormatProvider)
                });
            }

            if (logEvent.FirstOccurance != logEvent.LastOccurance)
            {
                yield return(new MicrosoftTeamsMessageFact
                {
                    Name = "First occurence",
                    Value = logEvent.FirstOccurance.ToString(
                        "dd.MM.yyyy HH:mm:sszzz",
                        _options.FormatProvider)
                });

                yield return(new MicrosoftTeamsMessageFact
                {
                    Name = "Last occurance",
                    Value = logEvent.LastOccurance.ToString(
                        "dd.MM.yyyy HH:mm:sszzz",
                        _options.FormatProvider)
                });
            }
            else
            {
                yield return(new MicrosoftTeamsMessageFact
                {
                    Name = "Occured on",
                    Value = logEvent.FirstOccurance.ToString(
                        "dd.MM.yyyy HH:mm:sszzz",
                        _options.FormatProvider)
                });
            }
        }
Пример #3
0
        /// <summary>
        /// Creates the message.
        /// </summary>
        /// <param name="logEvent">The log event.</param>
        /// <returns>A message card.</returns>
        private MicrosoftTeamsMessageCard CreateMessage(ExtendedLogEvent logEvent)
        {
            var renderedMessage = logEvent.LogEvent.RenderMessage(this.options.FormatProvider);

            var request = new MicrosoftTeamsMessageCard
            {
                Title    = this.options.Title,
                Text     = renderedMessage,
                Color    = GetAttachmentColor(logEvent.LogEvent.Level),
                Sections = this.options.OmitPropertiesSection ? null : new[]
                {
                    new MicrosoftTeamsMessageSection
                    {
                        Title = "Properties",
                        Facts = this.GetFacts(logEvent).ToArray()
                    }
                }
            };

            return(request);
        }