コード例 #1
0
        /// <devdoc>
        /// </devdoc>
        internal void Dispose(bool disposing) {
            try {
                if (disposing) {
                    //Dispose unmanaged and managed resources
                    if (IsOpen) {
                        Close();
                    }

                    // This is probably unnecessary
                    if (readHandle != null) {
                    readHandle.Close();
                        readHandle = null;
                    }

                    if (writeHandle != null) {
                    writeHandle.Close();
                        writeHandle = null;
                    }
                }
            }
            finally {
                messageLibraries = null;
                this.boolFlags[Flag_disposed] = true;
            }
        }
コード例 #2
0
        public EventLogInternal(string logName, string machineName, string source, EventLog parent) {
            //look out for invalid log names
            if (logName == null)
                throw new ArgumentNullException("logName");
            if (!ValidLogName(logName, true))
                throw new ArgumentException(SR.GetString(SR.BadLogName));

            if (!SyntaxCheck.CheckMachineName(machineName))
                throw new ArgumentException(SR.GetString(SR.InvalidParameter, "machineName", machineName));

            EventLogPermission permission = new EventLogPermission(EventLogPermissionAccess.Write, machineName);
            permission.Demand();
            
            this.machineName = machineName;

            this.logName = logName;
            this.sourceName = source;
            readHandle = null;
            writeHandle = null;
            boolFlags[Flag_forwards] = true;
            this.parent = parent;
        }
コード例 #3
0
        private void Close(string currentMachineName) {
            EventLogPermission permission = new EventLogPermission(EventLogPermissionAccess.Write, currentMachineName);
            permission.Demand();

            Debug.WriteLineIf(CompModSwitches.EventLog.TraceVerbose, "EventLog::Close");
            //Trace("Close", "Closing the event log");
            if (readHandle != null) {
                try {
                    readHandle.Close();
                }
                catch (IOException) {
                    throw SharedUtils.CreateSafeWin32Exception();
                }
                readHandle = null;
                //Trace("Close", "Closed read handle");
                Debug.WriteLineIf(CompModSwitches.EventLog.TraceVerbose, "EventLog::Close: closed read handle");
            }
            if (writeHandle != null) {
                try {
                    writeHandle.Close();
                }
                catch (IOException) {
                    throw SharedUtils.CreateSafeWin32Exception();
                }
                writeHandle = null;
                //Trace("Close", "Closed write handle");
                Debug.WriteLineIf(CompModSwitches.EventLog.TraceVerbose, "EventLog::Close: closed write handle");
            }
            if (boolFlags[Flag_monitoring])
                StopRaisingEvents(/*currentMachineName,*/ GetLogName(currentMachineName));

            if (messageLibraries != null) {
                foreach (SafeLibraryHandle handle in messageLibraries.Values)
                    handle.Close();

                messageLibraries = null;
            }
            
            boolFlags[Flag_sourceVerified] = false;
        }
コード例 #4
0
        private void OpenForRead(string currentMachineName) {
            Debug.WriteLineIf(CompModSwitches.EventLog.TraceVerbose, "EventLog::OpenForRead");

            EventLogPermission permission = new EventLogPermission(EventLogPermissionAccess.Administer, currentMachineName);
            permission.Demand();

            //Cannot allocate the readHandle if the object has been disposed, since finalization has been suppressed.
            if (this.boolFlags[Flag_disposed])
                throw new ObjectDisposedException(GetType().Name);

            string logname = GetLogName(currentMachineName);

            if (logname == null || logname.Length==0)
                throw new ArgumentException(SR.GetString(SR.MissingLogProperty));

            if (!EventLog.Exists(logname, currentMachineName) )        // do not open non-existing Log [[....]]
                throw new InvalidOperationException( SR.GetString(SR.LogDoesNotExists, logname, currentMachineName) );
            //Check environment before calling api
            SharedUtils.CheckEnvironment();

            // Clean up cache variables.
            // [[....]] The initilizing code is put here to guarantee, that first read of events
            //           from log file will start by filling up the cache buffer.
            lastSeenEntry = 0;
            lastSeenPos = 0;
            bytesCached = 0;
            firstCachedEntry = -1;

            SafeEventLogReadHandle handle = SafeEventLogReadHandle.OpenEventLog(currentMachineName, logname);
            if (handle.IsInvalid) {
                Win32Exception e = null;
                if (Marshal.GetLastWin32Error() != 0) {
                    e = SharedUtils.CreateSafeWin32Exception();
                }

                throw new InvalidOperationException(SR.GetString(SR.CantOpenLog, logname.ToString(), currentMachineName), e);
            }

            readHandle = handle;
        }
 public EventLogInternal(string logName, string machineName, string source, EventLog parent)
 {
     this.firstCachedEntry = -1;
     this.boolFlags = new BitVector32();
     if (logName == null)
     {
         throw new ArgumentNullException("logName");
     }
     if (!ValidLogName(logName, true))
     {
         throw new ArgumentException(SR.GetString("BadLogName"));
     }
     if (!SyntaxCheck.CheckMachineName(machineName))
     {
         throw new ArgumentException(SR.GetString("InvalidParameter", new object[] { "machineName", machineName }));
     }
     new EventLogPermission(EventLogPermissionAccess.Write, machineName).Demand();
     this.machineName = machineName;
     this.logName = logName;
     this.sourceName = source;
     this.readHandle = null;
     this.writeHandle = null;
     this.boolFlags[2] = true;
     this.m_Parent = parent;
 }
 internal void Dispose(bool disposing)
 {
     try
     {
         if (disposing)
         {
             if (this.IsOpen)
             {
                 this.Close();
             }
             if (this.readHandle != null)
             {
                 this.readHandle.Close();
                 this.readHandle = null;
             }
             if (this.writeHandle != null)
             {
                 this.writeHandle.Close();
                 this.writeHandle = null;
             }
         }
     }
     finally
     {
         this.messageLibraries = null;
         this.boolFlags[0x100] = true;
     }
 }
 private void Close(string currentMachineName)
 {
     new EventLogPermission(EventLogPermissionAccess.Write, currentMachineName).Demand();
     if (this.readHandle != null)
     {
         try
         {
             this.readHandle.Close();
         }
         catch (IOException)
         {
             throw SharedUtils.CreateSafeWin32Exception();
         }
         this.readHandle = null;
     }
     if (this.writeHandle != null)
     {
         try
         {
             this.writeHandle.Close();
         }
         catch (IOException)
         {
             throw SharedUtils.CreateSafeWin32Exception();
         }
         this.writeHandle = null;
     }
     if (this.boolFlags[8])
     {
         this.StopRaisingEvents(this.GetLogName(currentMachineName));
     }
     if (this.messageLibraries != null)
     {
         foreach (Microsoft.Win32.SafeHandles.SafeLibraryHandle handle in this.messageLibraries.Values)
         {
             handle.Close();
         }
         this.messageLibraries = null;
     }
     this.boolFlags[0x200] = false;
 }
 private void OpenForRead(string currentMachineName)
 {
     new EventLogPermission(EventLogPermissionAccess.Administer, currentMachineName).Demand();
     if (this.boolFlags[0x100])
     {
         throw new ObjectDisposedException(base.GetType().Name);
     }
     string logName = this.GetLogName(currentMachineName);
     if ((logName == null) || (logName.Length == 0))
     {
         throw new ArgumentException(SR.GetString("MissingLogProperty"));
     }
     if (!Exists(logName, currentMachineName))
     {
         throw new InvalidOperationException(SR.GetString("LogDoesNotExists", new object[] { logName, currentMachineName }));
     }
     SharedUtils.CheckEnvironment();
     this.lastSeenEntry = 0;
     this.lastSeenPos = 0;
     this.bytesCached = 0;
     this.firstCachedEntry = -1;
     this.readHandle = SafeEventLogReadHandle.OpenEventLog(currentMachineName, logName);
     if (this.readHandle.IsInvalid)
     {
         Win32Exception innerException = null;
         if (Marshal.GetLastWin32Error() != 0)
         {
             innerException = SharedUtils.CreateSafeWin32Exception();
         }
         throw new InvalidOperationException(SR.GetString("CantOpenLog", new object[] { logName.ToString(), currentMachineName }), innerException);
     }
 }