protected override void OnAttached() { _generateMessage = new HandlebarsTemplate(Host, !string.IsNullOrWhiteSpace(AlertMessage) ? AlertMessage : "{{$Message}}"); _generateDescription = new HandlebarsTemplate(Host, !string.IsNullOrWhiteSpace(AlertDescription) ? AlertDescription : $"Generated by Seq running at {Host.BaseUri}."); if (!string.IsNullOrEmpty(PriorityProperty)) _priorityProperty = PriorityProperty; if (!string.IsNullOrEmpty(DefaultPriority) && Enum.TryParse(DefaultPriority, true, out Priority defaultPriority)) _defaultPriority = defaultPriority; switch (string.IsNullOrEmpty(EventPriority)) { case false when EventPriority.Contains("="): { if (TryParsePriorityMappings(EventPriority, out var mappings)) { _isPriorityMapping = true; foreach (var mapping in mappings) _priorities.Add(mapping.Key, mapping.Value); Log.ForContext("Priority", _priorities, true).Debug("Priority Mappings: {Priority}"); } else { Log.ForContext("Priority", _defaultPriority).Debug( "Cannot parse priority type in Priority configuration '{EventPriority}' - cannot add these priority mappings; will use default of '{Priority}'", EventPriority); _priority = _defaultPriority; } break; } case false when Enum.TryParse(EventPriority, true, out Priority singlePriority): _priority = singlePriority; Log.ForContext("Priority", _priority).Debug("Priority: {Priority}"); break; default: Log.ForContext("Priority", _defaultPriority).Debug( "Priority configuration '{EventPriority}' not matched - will use default of '{Priority}'", EventPriority); _priority = _defaultPriority; break; } //Only map responders to a property if a valid responder mapping and default responders exist if (!string.IsNullOrEmpty(ResponderProperty) && !string.IsNullOrEmpty(Responders) && !string.IsNullOrEmpty(DefaultResponders)) { _responderProperty = ResponderProperty; _isResponderMapping = true; Log.ForContext("ResponderProperty", _responderProperty) .Debug("Map Responder Property: {ResponderProperty}"); } else if (!string.IsNullOrEmpty(ResponderProperty) || !string.IsNullOrEmpty(DefaultResponders)) { Log.Debug( "Responder Property Mapping not performed, Responder Property set: {ResponderProperty}, Responders set: {Responders}, Default Responders set: {DefaultResponders}", !string.IsNullOrEmpty(ResponderProperty), !string.IsNullOrEmpty(Responders), !string.IsNullOrEmpty(DefaultResponders)); } if (!string.IsNullOrEmpty(Responders)) { foreach (var responder in SplitAndTrim(',', Responders)) { if (responder.Contains("=")) { var r = SplitAndTrim('=', responder).ToArray(); if (Enum.TryParse(r[1], true, out ResponderType responderType)) _responders.Add(responderType == ResponderType.User ? new Responder {Username = r[0], Type = responderType} : new Responder {Name = r[0], Type = responderType}); else Log.Debug( "Cannot parse responder type in Responder configuration '{Responder}' - cannot add this responder", responder); } else { //Unmatched Name=Type defaults to Team _responders.Add(new Responder {Name = responder, Type = ResponderType.Team}); } } Log.ForContext("Responders", _responders, true) .Debug(_isResponderMapping ? "Responder Mappings: {Responders}" : "Responders: {Responders}"); } else { Log.Debug("No Responders specified, responders will not be passed to OpsGenie"); } // Assign default responders where they can be matched if (_isResponderMapping && !string.IsNullOrEmpty(DefaultResponders)) { _defaultResponders.AddRange( from r in SplitAndTrim(',', DefaultResponders) from p in _responders where r.Equals(p.Name, StringComparison.OrdinalIgnoreCase) || r.Equals(p.Username, StringComparison.OrdinalIgnoreCase) select p); Log.ForContext("DefaultResponders", _defaultResponders, true) .Debug("Default Responders: {DefaultResponders}"); } _tags = SplitAndTrim(',', Tags ?? "").ToArray(); _includeTags = AddEventTags; _includeTagProperty = "Tags"; if (!string.IsNullOrEmpty(AddEventProperty)) _includeTagProperty = AddEventProperty; Log.ForContext("Tags", _tags).ForContext("IncludeTags", _includeTags) .ForContext("IncludeEventTags", _includeTagProperty) .Debug("Tags: {Tags}, IncludeTags: {IncludeTags}, Include Event Tags: {IncludeEventTags}"); if (ApiClient != null) return; var client = new OpsgenieApiClient(ApiKey); ApiClient = client; _disposeClient = client; }