@@ -9,11 +9,19 @@ namespace WooCode.Slack.WebHooks
99{
1010 public class Message
1111 {
12+ private string _channel ;
13+
1214 [ JsonIgnore ]
1315 public string HookUrl { get ; set ; }
1416
1517 public string Text { get ; set ; }
16- public string Channel { get ; set ; }
18+
19+ public string Channel
20+ {
21+ get { return _channel ; }
22+ set { _channel = value . StartsWith ( "#" ) ? value : "#" + value ; }
23+ }
24+
1725 public string UserName { get ; set ; }
1826 [ JsonProperty ( PropertyName = "icon_url" ) ]
1927 public string IconUrl { get ; set ; }
@@ -47,28 +55,5 @@ public Message(string text, string channel = null, string userName = null) : thi
4755 Channel = channel ?? Channel ;
4856 UserName = userName ?? UserName ;
4957 }
50-
51- public void AttachException < T > ( T exception ) where T : Exception
52- {
53- var attachment = new Attachment
54- {
55- Color = AttachmentColor . Danger
56- } ;
57- attachment . Fields . Add ( new AttachmentField ( ) { Title = "Type" , Value = exception . GetType ( ) . FullName , Short = true } ) ;
58- attachment . Fields . Add ( new AttachmentField ( ) { Title = "Message" , Value = exception . Message , Short = true } ) ;
59-
60- if ( exception . StackTrace != null )
61- attachment . Fields . Add ( new AttachmentField ( ) { Title = "StackTrace" , Value = exception . StackTrace , Short = false } ) ;
62-
63- if ( exception . InnerException != null )
64- {
65- attachment . Fields . Add ( new AttachmentField ( ) { Title = "InnerException Type" , Value = exception . InnerException . GetType ( ) . FullName , Short = true } ) ;
66- attachment . Fields . Add ( new AttachmentField ( ) { Title = "InnerException Message" , Value = exception . InnerException . Message , Short = true } ) ;
67- if ( exception . InnerException . StackTrace != null )
68- attachment . Fields . Add ( new AttachmentField ( ) { Title = "InnerException StackTrace" , Value = exception . InnerException . StackTrace , Short = false } ) ;
69- }
70-
71- Attachments . Add ( attachment ) ;
72- }
7358 }
7459}
0 commit comments