* EventLog.cs: Fixed Designer attribute to match MS.NET.
[mono.git] / mcs / class / System / System.Diagnostics / EventLog.cs
1 //
2 // System.Diagnostics.EventLog.cs
3 //
4 // Authors:
5 //   Jonathan Pryor (jonpryor@vt.edu)
6 //   Andreas Nahr (ClassDevelopment@A-SoftTech.com)
7 //
8 // (C) 2002
9 // (C) 2003 Andreas Nahr
10 //
11
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 //
32
33 using System;
34 using System.Diagnostics;
35 using System.ComponentModel;
36 using System.ComponentModel.Design;
37
38 namespace System.Diagnostics 
39 {
40         [DefaultEvent ("EntryWritten")]
41         [InstallerType (typeof (EventLogInstaller))]
42         [Designer ("Microsoft.VisualStudio.Install.EventLogInstallableComponentDesigner, " + Consts.AssemblyMicrosoft_VisualStudio)]
43         public class EventLog : Component, ISupportInitialize 
44         {
45
46                 private string source;
47                 private string logName;
48                 private string machineName;
49                 private bool doRaiseEvents = false;
50                 private ISynchronizeInvoke synchronizingObject = null;
51
52                 private EventLogImpl Impl;
53
54                 public EventLog()
55                         : this ("")
56                 {
57                 }
58
59                 public EventLog(string logName)
60                         : this (logName, ".")
61                 {
62                 }
63
64                 public EventLog(string logName, string machineName) 
65                         : this (logName, machineName, "")
66                 {
67                 }
68
69                 public EventLog(string logName, string machineName, string source)
70                 {
71                         this.source = source;
72                         this.machineName = machineName;
73                         this.logName = logName;
74
75                         this.Impl = new EventLogImpl (this);
76                         EventLogImpl.EntryWritten += new EntryWrittenEventHandler (EntryWrittenHandler);
77                 }
78
79                 private void EntryWrittenHandler (object sender, EntryWrittenEventArgs e)
80                 {
81                         if (doRaiseEvents)
82                                 OnEntryWritten (e.Entry);
83                 }
84
85                 [Browsable (false), DefaultValue (false)]
86                 [MonitoringDescription ("If enabled raises event when a log is written.")]
87                 public bool EnableRaisingEvents {
88                         get {return doRaiseEvents;}
89                         set {doRaiseEvents = value;}
90                 }
91
92                 [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
93                 [MonitoringDescription ("The entries in the log.")]
94                 public EventLogEntryCollection Entries {
95                         get {return Impl.Entries;}
96                 }
97
98                 [ReadOnly (true), DefaultValue (""), RecommendedAsConfigurable (true)]
99                 [TypeConverter ("System.Diagnostics.Design.LogConverter, " + Consts.AssemblySystem_Design)]
100                 [MonitoringDescription ("Name of the log that is read and written.")]
101                 public string Log {
102                         get {return logName;}
103                         set {logName = value;}
104                 }
105
106                 [Browsable (false)]
107                 public string LogDisplayName {
108                         get {return Impl.LogDisplayName;}
109                 }
110
111                 [ReadOnly (true), DefaultValue ("."), RecommendedAsConfigurable (true)]
112                 [MonitoringDescription ("Name of the machine that this log get written to.")]
113                 public string MachineName {
114                         get {return machineName;}
115                         set {machineName = value;}
116                 }
117
118                 [ReadOnly (true), DefaultValue (""), RecommendedAsConfigurable (true)]
119                 [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
120                 [MonitoringDescription ("The application name that writes the log.")]
121                 public string Source {
122                         get {return source;}
123                         set {source = value;}
124                 }
125
126                 [Browsable (false), DefaultValue (null)]
127                 [MonitoringDescription ("An object that synchronizes event handler calls.")]
128                 public ISynchronizeInvoke SynchronizingObject {
129                         get {return synchronizingObject;}
130                         set {synchronizingObject = value;}
131                 }
132
133                 public void BeginInit()
134                 {
135                         Impl.BeginInit();
136                 }
137
138                 public void Clear()
139                 {
140                         Impl.Clear();
141                 }
142
143                 public void Close()
144                 {
145                         Impl.Close();
146                 }
147
148                 public static void CreateEventSource(string source, string logName)
149                 {
150                         CreateEventSource (source, logName, ".");
151                 }
152
153                 public static void CreateEventSource(string source, 
154                         string logName, 
155                         string machineName)
156                 {
157                         EventLogImpl.CreateEventSource (source, logName, machineName);
158                 }
159
160                 public static void Delete(string logName)
161                 {
162                         Delete (logName, ".");
163                 }
164
165                 public static void Delete(string logName, string machineName)
166                 {
167                         EventLogImpl.Delete (logName, machineName);
168                 }
169
170                 public static void DeleteEventSource(string source)
171                 {
172                         DeleteEventSource (source, ".");
173                 }
174
175                 public static void DeleteEventSource(string source, 
176                         string machineName)
177                 {
178                         EventLogImpl.DeleteEventSource (source, machineName);
179                 }
180
181                 protected override void Dispose(bool disposing)
182                 {
183                         Impl.Dispose (disposing);
184                 }
185
186                 public void EndInit()
187                 {
188                         Impl.EndInit();
189                 }
190
191                 public static bool Exists(string logName)
192                 {
193                         return Exists (logName, ".");
194                 }
195
196                 public static bool Exists(string logName, string machineName)
197                 {
198                         return EventLogImpl.Exists (logName, machineName);
199                 }
200
201                 public static EventLog[] GetEventLogs()
202                 {
203                         return GetEventLogs (".");
204                 }
205
206                 public static EventLog[] GetEventLogs(string machineName)
207                 {
208                         return EventLogImpl.GetEventLogs (machineName);
209                 }
210
211                 public static string LogNameFromSourceName(string source, 
212                         string machineName)
213                 {
214                         return EventLogImpl.LogNameFromSourceName (source, machineName);
215                 }
216
217                 public static bool SourceExists(string source)
218                 {
219                         return SourceExists (source, ".");
220                 }
221
222                 public static bool SourceExists(string source, string machineName)
223                 {
224                         return EventLogImpl.SourceExists (source, machineName);
225                 }
226
227                 public void WriteEntry(string message)
228                 {
229                         WriteEntry (message, EventLogEntryType.Information);
230                 }
231
232                 public void WriteEntry(string message, EventLogEntryType type)
233                 {
234                         WriteEntry (message, type, 0);
235                 }
236
237                 public void WriteEntry(string message, EventLogEntryType type, 
238                         int eventID)
239                 {
240                         WriteEntry (message, type, eventID, 0);
241                 }
242
243                 public void WriteEntry(string message, EventLogEntryType type, 
244                         int eventID,
245                         short category)
246                 {
247                         WriteEntry (message, type, eventID, category, null);
248                 }
249
250                 public void WriteEntry(string message, EventLogEntryType type, 
251                         int eventID,
252                         short category, byte[] rawData)
253                 {
254                         Impl.WriteEntry (message, type, eventID, category, rawData);
255                 }
256
257                 public static void WriteEntry(string source, string message)
258                 {
259                         WriteEntry (source, message, EventLogEntryType.Information);
260                 }
261
262                 public static void WriteEntry(string source, string message, 
263                         EventLogEntryType type)
264                 {
265                         WriteEntry (source, message, EventLogEntryType.Information, 0);
266                 }
267
268                 public static void WriteEntry(string source, string message, 
269                         EventLogEntryType type, int eventID)
270                 {
271                         WriteEntry (source, message, EventLogEntryType.Information, eventID, 0);
272                 }
273
274                 public static void WriteEntry(string source, string message, 
275                         EventLogEntryType type, int eventID, short category)
276                 {
277                         WriteEntry (source, message, EventLogEntryType.Information, eventID, category, null);
278                 }
279
280                 public static void WriteEntry(string source, string message, 
281                         EventLogEntryType type, int eventID, short category, 
282                         byte[] rawData)
283                 {
284                         EventLogImpl.WriteEntry (source, message, type, eventID, category, rawData);
285                 }
286
287                 internal void OnEntryWritten (EventLogEntry newEntry)
288                 {
289                         if (EntryWritten != null)
290                                 EntryWritten (this, new EntryWrittenEventArgs (newEntry));
291                 }
292
293                 [MonitoringDescription ("Raised for each EventLog entry written.")]
294                 public event EntryWrittenEventHandler EntryWritten;
295         }
296 }
297