Merge branch 'master'
[mono.git] / mcs / class / corlib / System.Diagnostics.Tracing / EventSource.cs
1 //
2 // EventSource.cs
3 //
4 // Authors:
5 //      Marek Safar  <marek.safar@gmail.com>
6 //      Frederik Carlier <frederik.carlier@quamotion.mobi>
7 //
8 // Copyright (C) 2014 Xamarin Inc (http://www.xamarin.com)
9 // Copyrithg (C) 2015 Quamotion (http://quamotion.mobi)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31
32 namespace System.Diagnostics.Tracing
33 {
34         public class EventSource : IDisposable
35         {
36                 protected EventSource ()
37                 {
38                         this.Name = this.GetType().Name;
39                 }
40
41                 protected EventSource (bool throwOnEventWriteErrors)
42                         : this ()
43                 {
44                 }
45
46                 protected EventSource (EventSourceSettings settings)
47                         : this ()
48                 {
49                         this.Settings = settings;
50                 }
51
52                 protected EventSource (EventSourceSettings settings, params string[] traits)
53                         : this (settings)
54                 {
55                 }
56
57                 public EventSource (string eventSourceName)
58                 {
59                         this.Name = eventSourceName;
60                 }
61
62                 public EventSource (string eventSourceName, EventSourceSettings config)
63                         : this (eventSourceName)
64                 {
65                         this.Settings = config;
66                 }
67
68                 public EventSource (string eventSourceName, EventSourceSettings config, params string[] traits)
69                         : this (eventSourceName, config)
70                 {
71                 }
72
73                 public Exception ConstructionException
74                 {
75                         get { return null; }
76                 }
77
78                 public static Guid CurrentThreadActivityId
79                 {
80                         get { return Guid.Empty; }
81                 }
82
83                 public Guid Guid
84                 {
85                         get { return Guid.Empty; }
86                 }
87
88                 public string Name
89                 {
90                         get;
91                         private set;
92                 }
93
94                 public EventSourceSettings Settings
95                 {
96                         get;
97                         private set;
98                 }
99
100                 public bool IsEnabled ()
101                 {
102                         return false;
103                 }
104
105                 public bool IsEnabled (EventLevel level, EventKeywords keywords)
106                 {
107                         return false;
108                 }
109
110                 public bool IsEnabled (EventLevel level, EventKeywords keywords, EventChannel channel)
111                 {
112                         return false;
113                 }
114
115                 public void Dispose ()
116                 {
117                         Dispose (true);
118                 }
119
120                 public string GetTrait (string key)
121                 {
122                         return null;
123                 }
124
125                 public void Write (string eventName)
126                 {
127                 }
128
129 #if NET_4_6
130                 public void Write<T> (string eventName, T data)
131                 {
132                 }
133
134                 public void Write<T> (string eventName, EventSourceOptions options, T data)
135                 {
136                 }
137
138                 public void Write<T> (string eventName, ref EventSourceOptions options, ref T data)
139                 {
140                 }
141
142                 public void Write<T> (string eventName, ref EventSourceOptions options, ref Guid activityId, ref Guid relatedActivityId, ref T data)
143                 {
144                 }
145 #endif
146
147                 protected virtual void Dispose (bool disposing)
148                 {
149                 }
150
151                 protected virtual void OnEventCommand (EventCommandEventArgs command)
152                 {
153                 }
154
155                 protected void WriteEvent (int eventId)
156                 {
157                         WriteEvent (eventId, new object[] { } );
158                 }
159
160                 protected void WriteEvent (int eventId, byte[] arg1)
161                 {
162                         WriteEvent (eventId, new object[] { arg1 } );
163                 }
164
165                 protected void WriteEvent (int eventId, int arg1)
166                 {
167                         WriteEvent (eventId, new object[] { arg1 } );
168                 }
169
170                 protected void WriteEvent (int eventId, string arg1)
171                 {
172                         WriteEvent (eventId, new object[] { arg1 } );
173                 }
174
175                 protected void WriteEvent (int eventId, int arg1, int arg2)
176                 {
177                         WriteEvent (eventId, new object[] { arg1, arg2 } );
178                 }
179
180                 protected void WriteEvent (int eventId, int arg1, int arg2, int arg3)
181                 {
182                         WriteEvent (eventId, new object[] { arg1, arg2, arg3 } );
183                 }
184
185                 protected void WriteEvent (int eventId, int arg1, string arg2)
186                 {
187                         WriteEvent (eventId, new object[] { arg1, arg2 } );
188                 }
189
190                 protected void WriteEvent (int eventId, long arg1)
191                 {
192                         WriteEvent (eventId, new object[] { arg1 } );
193                 }
194
195                 protected void WriteEvent (int eventId, long arg1, byte[] arg2)
196                 {
197                         WriteEvent (eventId, new object[] { arg1, arg2 } );
198                 }
199
200                 protected void WriteEvent (int eventId, long arg1, long arg2)
201                 {
202                         WriteEvent (eventId, new object[] { arg1, arg2 } );
203                 }
204
205                 protected void WriteEvent (int eventId, long arg1, long arg2, long arg3)
206                 {
207                         WriteEvent (eventId, new object[] { arg1, arg2, arg3 } );
208                 }
209
210                 protected void WriteEvent (int eventId, long arg1, string arg2)
211                 {
212                         WriteEvent (eventId, new object[] { arg1, arg2 } );
213                 }
214
215                 protected void WriteEvent (int eventId, params object[] args)
216                 {
217                 }
218
219                 protected void WriteEvent (int eventId, string arg1, int arg2)
220                 {
221                         WriteEvent (eventId, new object[] { arg1, arg2 } );
222                 }
223
224                 protected void WriteEvent (int eventId, string arg1, int arg2, int arg3)
225                 {
226                         WriteEvent (eventId, new object[] { arg1, arg2, arg3 } );
227                 }
228
229                 protected void WriteEvent (int eventId, string arg1, long arg2)
230                 {
231                         WriteEvent (eventId, new object[] { arg1, arg2 } );
232                 }
233
234                 protected void WriteEvent (int eventId, string arg1, string arg2)
235                 {
236                         WriteEvent (eventId, new object[] { arg1, arg2 } );
237                 }
238
239                 protected void WriteEvent (int eventId, string arg1, string arg2, string arg3)
240                 {
241                         WriteEvent (eventId, new object[] { arg1, arg2, arg3 } );
242                 }
243         }
244 }
245