| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- //
- // System.Diagnostics.EventLog.cs
- //
- // Authors:
- // Jonathan Pryor ([email protected])
- // Andreas Nahr ([email protected])
- //
- // (C) 2002
- // (C) 2003 Andreas Nahr
- //
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- using System;
- using System.Diagnostics;
- using System.ComponentModel;
- using System.ComponentModel.Design;
- namespace System.Diagnostics
- {
- [DefaultEvent ("EntryWritten"), InstallerType (typeof (EventLogInstaller))]
- [Designer ("Microsoft.VisualStudio.Install.EventLogInstallableComponentDesigner, " + Consts.AssemblyMicrosoft_VisualStudio, typeof (IDesigner))]
- public class EventLog : Component, ISupportInitialize
- {
- private string source;
- private string logName;
- private string machineName;
- private bool doRaiseEvents = false;
- private ISynchronizeInvoke synchronizingObject = null;
- private EventLogImpl Impl;
- public EventLog()
- : this ("")
- {
- }
- public EventLog(string logName)
- : this (logName, ".")
- {
- }
- public EventLog(string logName, string machineName)
- : this (logName, machineName, "")
- {
- }
- public EventLog(string logName, string machineName, string source)
- {
- this.source = source;
- this.machineName = machineName;
- this.logName = logName;
- this.Impl = new EventLogImpl (this);
- EventLogImpl.EntryWritten += new EntryWrittenEventHandler (EntryWrittenHandler);
- }
- private void EntryWrittenHandler (object sender, EntryWrittenEventArgs e)
- {
- if (doRaiseEvents)
- OnEntryWritten (e.Entry);
- }
- [Browsable (false), DefaultValue (false)]
- [MonitoringDescription ("If enabled raises event when a log is written.")]
- public bool EnableRaisingEvents {
- get {return doRaiseEvents;}
- set {doRaiseEvents = value;}
- }
- [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
- [MonitoringDescription ("The entries in the log.")]
- public EventLogEntryCollection Entries {
- get {return Impl.Entries;}
- }
- [ReadOnly (true), DefaultValue (""), RecommendedAsConfigurable (true)]
- [TypeConverter ("System.Diagnostics.Design.LogConverter, " + Consts.AssemblySystem_Design)]
- [MonitoringDescription ("Name of the log that is read and written.")]
- public string Log {
- get {return logName;}
- set {logName = value;}
- }
- [Browsable (false)]
- public string LogDisplayName {
- get {return Impl.LogDisplayName;}
- }
- [ReadOnly (true), DefaultValue ("."), RecommendedAsConfigurable (true)]
- [MonitoringDescription ("Name of the machine that this log get written to.")]
- public string MachineName {
- get {return machineName;}
- set {machineName = value;}
- }
- [ReadOnly (true), DefaultValue (""), RecommendedAsConfigurable (true)]
- [TypeConverter ("System.Diagnostics.Design.StringValueConverter, " + Consts.AssemblySystem_Design)]
- [MonitoringDescription ("The application name that writes the log.")]
- public string Source {
- get {return source;}
- set {source = value;}
- }
- [Browsable (false), DefaultValue (null)]
- [MonitoringDescription ("An object that synchronizes event handler calls.")]
- public ISynchronizeInvoke SynchronizingObject {
- get {return synchronizingObject;}
- set {synchronizingObject = value;}
- }
- public void BeginInit()
- {
- Impl.BeginInit();
- }
- public void Clear()
- {
- Impl.Clear();
- }
- public void Close()
- {
- Impl.Close();
- }
- public static void CreateEventSource(string source, string logName)
- {
- CreateEventSource (source, logName, ".");
- }
- public static void CreateEventSource(string source,
- string logName,
- string machineName)
- {
- EventLogImpl.CreateEventSource (source, logName, machineName);
- }
- public static void Delete(string logName)
- {
- Delete (logName, ".");
- }
- public static void Delete(string logName, string machineName)
- {
- EventLogImpl.Delete (logName, machineName);
- }
- public static void DeleteEventSource(string source)
- {
- DeleteEventSource (source, ".");
- }
- public static void DeleteEventSource(string source,
- string machineName)
- {
- EventLogImpl.DeleteEventSource (source, machineName);
- }
- protected override void Dispose(bool disposing)
- {
- Impl.Dispose (disposing);
- }
- public void EndInit()
- {
- Impl.EndInit();
- }
- public static bool Exists(string logName)
- {
- return Exists (logName, ".");
- }
- public static bool Exists(string logName, string machineName)
- {
- return EventLogImpl.Exists (logName, machineName);
- }
- public static EventLog[] GetEventLogs()
- {
- return GetEventLogs (".");
- }
- public static EventLog[] GetEventLogs(string machineName)
- {
- return EventLogImpl.GetEventLogs (machineName);
- }
- public static string LogNameFromSourceName(string source,
- string machineName)
- {
- return EventLogImpl.LogNameFromSourceName (source, machineName);
- }
- public static bool SourceExists(string source)
- {
- return SourceExists (source, ".");
- }
- public static bool SourceExists(string source, string machineName)
- {
- return EventLogImpl.SourceExists (source, machineName);
- }
- public void WriteEntry(string message)
- {
- WriteEntry (message, EventLogEntryType.Information);
- }
- public void WriteEntry(string message, EventLogEntryType type)
- {
- WriteEntry (message, type, 0);
- }
- public void WriteEntry(string message, EventLogEntryType type,
- int eventID)
- {
- WriteEntry (message, type, eventID, 0);
- }
- public void WriteEntry(string message, EventLogEntryType type,
- int eventID,
- short category)
- {
- WriteEntry (message, type, eventID, category, null);
- }
- public void WriteEntry(string message, EventLogEntryType type,
- int eventID,
- short category, byte[] rawData)
- {
- Impl.WriteEntry (message, type, eventID, category, rawData);
- }
- public static void WriteEntry(string source, string message)
- {
- WriteEntry (source, message, EventLogEntryType.Information);
- }
- public static void WriteEntry(string source, string message,
- EventLogEntryType type)
- {
- WriteEntry (source, message, EventLogEntryType.Information, 0);
- }
- public static void WriteEntry(string source, string message,
- EventLogEntryType type, int eventID)
- {
- WriteEntry (source, message, EventLogEntryType.Information, eventID, 0);
- }
- public static void WriteEntry(string source, string message,
- EventLogEntryType type, int eventID, short category)
- {
- WriteEntry (source, message, EventLogEntryType.Information, eventID, category, null);
- }
- public static void WriteEntry(string source, string message,
- EventLogEntryType type, int eventID, short category,
- byte[] rawData)
- {
- EventLogImpl.WriteEntry (source, message, type, eventID, category, rawData);
- }
- internal void OnEntryWritten (EventLogEntry newEntry)
- {
- if (EntryWritten != null)
- EntryWritten (this, new EntryWrittenEventArgs (newEntry));
- }
- [MonitoringDescription ("Raised for each EventLog entry written.")]
- public event EntryWrittenEventHandler EntryWritten;
- }
- }
|