当前位置: 首页>>代码示例>>C#>>正文


C# EventLog.Clear方法代码示例

本文整理汇总了C#中System.Diagnostics.EventLog.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# EventLog.Clear方法的具体用法?C# EventLog.Clear怎么用?C# EventLog.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Diagnostics.EventLog的用法示例。


在下文中一共展示了EventLog.Clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

		/// <summary>
		/// ITestStep.Execute() implementation
		/// </summary>
		/// <param name='testConfig'>The Xml fragment containing the configuration for this test step</param>
		/// <param name='context'>The context for the test, this holds state that is passed beteen tests</param>
		public void Execute(XmlNode testConfig, Context context)
		{
			var rawListOfMachines = context.ReadConfigAsString(testConfig, "Machine", true);
            
            var listOfMachines = new List<string>();

            if (string.IsNullOrEmpty(rawListOfMachines))
            {
                listOfMachines.Add(Environment.MachineName);
            }
            else
            {
                listOfMachines.AddRange(rawListOfMachines.Split(','));
            }

            foreach (var machine in listOfMachines)
            {
                var eventLog = context.ReadConfigAsString(testConfig, "EventLog");

                using (var log = new EventLog(eventLog, machine))
                {
                    context.LogInfo("About to clear the '{0}' event log on machine '{1}'of all entries.", eventLog,
                                    machine);
                    log.Clear();
                }
            }
		}
开发者ID:RobBowman,项目名称:BizUnit,代码行数:32,代码来源:EventLogClearStep.cs

示例2: isSimpleEntryWriten

 public void isSimpleEntryWriten()
 {
     EventLog ea=new EventLog("Test Log",".","Test Log");
     LogManager.Log("Hello world!");
     EventLogEntry[] entries=new EventLogEntry[ea.Entries.Count];
     ea.Entries.CopyTo(entries,0);
     Assertion.AssertEquals("Hello world!",entries[0].Message);
     ea.Clear();
 }
开发者ID:bage,项目名称:Demo-Logging-Wrapper,代码行数:9,代码来源:DiagnosticImplTestOld.cs

示例3: DeleteSource

        public static void DeleteSource(string source)
        {
            if (EventLog.SourceExists(source, Environment.MachineName))
            {
                EventLog.DeleteEventSource(source, Environment.MachineName); // Delete Source

                using (var elog = new EventLog(EventLogName, Environment.MachineName, source))
                {
                    elog.Clear();
                }
            }
            // recreate
            CreateEventLog();
        }
开发者ID:Behzadkhosravifar,项目名称:SignalR,代码行数:14,代码来源:WindowsEventLog.cs

示例4: MultiThreadToEventLogSink

        public void MultiThreadToEventLogSink()
        {
            using (EventLog log = new EventLog(customEventLog))
            {
                log.Clear();
            }

            ThreadStart testMethod = new ThreadStart(SendTestMessagesEventLog);

            base.ThreadStress(testMethod, threadCount);

            Thread.Sleep(500);

            int count = GetCountCustomEventLog();
            Assert.AreEqual(threadCount * loopCount, count);
        }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:16,代码来源:LoggerStressFixture.cs

示例5: ClearEventLog

 private void ClearEventLog()
 {
   base.setAction("Clearing EventLogs...");
   Update();
   int subActions = logNames.Length;
   foreach (string strLogName in logNames)
   {
     EventLog e = new EventLog(strLogName);
     try
     {
       e.Clear();
     }
     catch (Exception) {}
     updateProgress(subActions);
   }
   if (subActions == 0)
   {
     updateProgress(1);
   }
 }
开发者ID:arangas,项目名称:MediaPortal-1,代码行数:20,代码来源:PreTestActions.cs

示例6: WriteEvent

 public void WriteEvent(string strMessage, EventLogEntryType type)
 {
     if (!EventLog.SourceExists(this._sourece))
     EventLog.CreateEventSource(this._sourece, this._eventName);
       EventLog eventLog = new EventLog();
       eventLog.Log = this._eventName;
       eventLog.Source = this._sourece;
       try
       {
     eventLog.WriteEntry(strMessage, type);
       }
       catch (Exception ex)
       {
     eventLog.Clear();
     this.WriteEvent("日志文件已满,执行清除操作!", EventLogEntryType.Warning);
     eventLog.WriteEntry(strMessage, type);
       }
       finally
       {
     eventLog.Close();
     eventLog.Dispose();
       }
 }
开发者ID:wangyuanxun,项目名称:DataOperator,代码行数:23,代码来源:WriteLog.cs

示例7: Delete

        public static void Delete(string logName, string machineName) {

            if (!SyntaxCheck.CheckMachineName(machineName))
                throw new ArgumentException(SR.GetString(SR.InvalidParameterFormat, "machineName"));
            if (logName == null || logName.Length==0)
                throw new ArgumentException(SR.GetString(SR.NoLogName));
            if (!ValidLogName(logName, false))
                throw new InvalidOperationException(SR.GetString(SR.BadLogName));

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

            //Check environment before even trying to play with the registry
            SharedUtils.CheckEnvironment();

            //SECREVIEW: Note that EventLog permission is demanded above.
            PermissionSet permissionSet = _UnsafeGetAssertPermSet();
            permissionSet.Assert();
            
            RegistryKey eventlogkey = null;

            Mutex mutex = null;
            RuntimeHelpers.PrepareConstrainedRegions();
            try {
                SharedUtils.EnterMutex(eventLogMutexName, ref mutex);

                try {
                    eventlogkey  = GetEventLogRegKey(machineName, true);
                    if (eventlogkey  == null) {
                        // there's not even an event log service on the machine.
                        // or, more likely, we don't have the access to read the registry.
                        throw new InvalidOperationException(SR.GetString(SR.RegKeyNoAccess, "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\EventLog", machineName));
                    }

                    using (RegistryKey logKey = eventlogkey.OpenSubKey(logName)) {
                        if (logKey == null)
                            throw new InvalidOperationException(SR.GetString(SR.MissingLog, logName, machineName));

                        //clear out log before trying to delete it
                        //that way, if we can't delete the log file, no entries will persist because it has been cleared
                        EventLog logToClear = new EventLog(logName, machineName);
                        try {
                            logToClear.Clear();
                        }
                        finally {
                            logToClear.Close();
                        }

                        // 


                        string filename = null;
                        try {
                            //most of the time, the "File" key does not exist, but we'll still give it a whirl
                            filename = (string) logKey.GetValue("File");
                        }
                        catch { }
                        if (filename != null) {
                            try {
                                File.Delete(filename);
                            }
                            catch { }
                        }
                    }

                    // now delete the registry entry
                    eventlogkey.DeleteSubKeyTree(logName);
                }
                finally {
                    if (eventlogkey != null) eventlogkey.Close();
                
                    // Revert registry and environment permission asserts
                    CodeAccessPermission.RevertAssert();
                }
            }
            finally {
                if (mutex != null) mutex.ReleaseMutex();
            }
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:79,代码来源:EventLog.cs

示例8: Entries_Source_Null


//.........这里部分代码省略.........
						Assert.IsNull (ex.InnerException, "#G4");
					}
#else
					entry = (EventLogEntry) enumerator.Current;
					Assert.IsNotNull (entry, "#G1");
					Assert.IsNotNull (entry.Source, "#G2");
					Assert.AreEqual ("monotempsource", entry.Source, "#G3");
					Assert.IsNotNull (entry.ReplacementStrings, "#G4");
					Assert.AreEqual (1, entry.ReplacementStrings.Length, "#G5");
					Assert.AreEqual ("Entries_Source_Null2", entry.ReplacementStrings [0], "#G6");
#endif

					Assert.IsFalse (enumerator.MoveNext (), "#H1");
					Assert.AreEqual (2, eventLog.Entries.Count, "#H2");

					entries = new EventLogEntry [1];
					try {
						eventLog.Entries.CopyTo (entries, 0);
						Assert.Fail ("#I1");
					} catch (ArgumentException ex) {
						// Destination array was not long enough. Check destIndex
						// and length, and the array's lower bounds
						Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#I2");
						Assert.IsNotNull (ex.Message, "#I3");
						Assert.IsNull (ex.InnerException, "#I4");
#if NET_2_0
						Assert.AreEqual ("", ex.ParamName, "#I5");
#else
						Assert.IsNull (ex.ParamName, "#I5");
#endif
					}

					entries = new EventLogEntry [2];
					eventLog.Entries.CopyTo (entries, 0);

					entry = entries [0];
					Assert.IsNotNull (entry, "#J1");
					Assert.IsNotNull (entry.Source, "#J2");
					Assert.AreEqual ("monotempsource", entry.Source, "#J3");
					Assert.IsNotNull (entry.ReplacementStrings, "#J4");
					Assert.AreEqual (1, entry.ReplacementStrings.Length, "#J5");
					Assert.AreEqual ("Entries_Source_Null1", entry.ReplacementStrings [0], "#J6");

					entry = entries [1];
					Assert.IsNotNull (entry, "#K1");
					Assert.IsNotNull (entry.Source, "#K2");
					Assert.AreEqual ("monotempsource", entry.Source, "#K3");
					Assert.IsNotNull (entry.ReplacementStrings, "#K4");
					Assert.AreEqual (1, entry.ReplacementStrings.Length, "#K5");
					Assert.AreEqual ("Entries_Source_Null2", entry.ReplacementStrings [0], "#K6");

					Assert.IsFalse (enumerator.MoveNext (), "#L1");
					enumerator.Reset ();
					Assert.IsTrue (enumerator.MoveNext (), "#L2");
					Assert.IsNotNull (enumerator.Current, "#L3");
					Assert.IsTrue (enumerator.MoveNext (), "#L4");
					Assert.IsNotNull (enumerator.Current, "#L5");

					Assert.IsFalse (enumerator.MoveNext (), "#M1");
					enumerator.Reset ();
					Assert.IsTrue (enumerator.MoveNext (), "#M2");
					eventLog.Clear ();
#if NET_2_0
					Assert.IsNotNull (enumerator.Current, "#M3");
#else
					try {
						object current = enumerator.Current;
						Assert.Fail ("#M3a: " + current);
					} catch (InvalidOperationException ex) {
						// No current EventLog entry available, cursor is located
						// before the first or after the last element of the
						// enumeration
						Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#M3b");
						Assert.IsNotNull (ex.Message, "#M3c");
						Assert.IsNull (ex.InnerException, "#M3d");
					}
#endif
					Assert.IsFalse (enumerator.MoveNext (), "#M4");

					try {
						object current = enumerator.Current;
						Assert.Fail ("#N1: " + current);
					} catch (InvalidOperationException ex) {
						// No current EventLog entry available, cursor is located
						// before the first or after the last element of the
						// enumeration
						Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#N2");
						Assert.IsNotNull (ex.Message, "#N3");
						Assert.IsNull (ex.InnerException, "#N4");
					}

					Assert.IsFalse (enumerator.MoveNext (), "#O1");
					enumerator.Reset ();
					Assert.IsFalse (enumerator.MoveNext (), "#O2");
				}
			} finally {
				if (EventLog.Exists ("monologtemp"))
					EventLog.Delete ("monologtemp");
			}
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:101,代码来源:EventLogTest.cs

示例9: Clear_Log_DoesNotExist

		public void Clear_Log_DoesNotExist ()
		{
			if (EventLogImplType == NULL_IMPL)
				// test cannot pass with NULL implementation
				return;

			if (EventLog.Exists ("monologtemp", "."))
				Assert.Ignore ("Event log 'monologtemp' should not exist.");

			using (EventLog eventLog = new EventLog ("monologtemp", ".")) {
				try {
					eventLog.Clear ();
					Assert.Fail ("#1");
				} catch (InvalidOperationException ex) {
					// The event log 'monologtemp' on computer '.' does not exist
					Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#2");
					Assert.IsNotNull (ex.Message, "#3");
					Assert.IsTrue (ex.Message.IndexOf ("'monologtemp'") != -1, "#4");
					Assert.IsTrue (ex.Message.IndexOf ("'.'") != -1, "#5");
					Assert.IsNull (ex.InnerException, "#6");
				}
				Assert.IsFalse (EventLog.Exists ("monologtemp", "."), "#7");
			}
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:24,代码来源:EventLogTest.cs

示例10: ClearLogs

 private void ClearLogs()
 {
     EventLog oEventLog = new EventLog();
     oEventLog.Source = "Database";
     oEventLog.Clear();
 }
开发者ID:myoung1988,项目名称:DynastyBaseball,代码行数:6,代码来源:Error_Handling_Test.cs

示例11: BeginProcessing

 /// <summary>
 /// Does the processing
 /// </summary>
 protected override void BeginProcessing()
 {
     string computer = string.Empty;
     foreach (string compName in ComputerName)
     {
         if ((compName.Equals("localhost", StringComparison.CurrentCultureIgnoreCase)) || (compName.Equals(".", StringComparison.OrdinalIgnoreCase)))
         {
             computer = "localhost";
         }
         else
         {
             computer = compName;
         }
         foreach (string eventString in LogName)
         {
             try
             {
                 if (!EventLog.Exists(eventString, compName))
                 {
                     ErrorRecord er = new ErrorRecord(new InvalidOperationException(StringUtil.Format(EventlogResources.LogDoesNotExist, eventString, computer)), null, ErrorCategory.InvalidOperation, null);
                     WriteError(er);
                     continue;
                 }
                 if (!ShouldProcess(StringUtil.Format(EventlogResources.ClearEventLogWarning, eventString, computer)))
                 {
                     continue;
                 }
                 EventLog Log = new EventLog(eventString, compName);
                 Log.Clear();
             }
             catch (System.IO.IOException)
             {
                 ErrorRecord er = new ErrorRecord(new System.IO.IOException(StringUtil.Format(EventlogResources.PathDoesNotExist, null, computer)), null, ErrorCategory.InvalidOperation, null);
                 WriteError(er);
                 continue;
             }
             catch (Win32Exception)
             {
                 ErrorRecord er = new ErrorRecord(new Win32Exception(StringUtil.Format(EventlogResources.NoAccess, null, computer)), null, ErrorCategory.PermissionDenied, null);
                 WriteError(er);
                 continue;
             }
             catch (InvalidOperationException)
             {
                 ErrorRecord er = new ErrorRecord(new InvalidOperationException(StringUtil.Format(EventlogResources.OSWritingError)), null, ErrorCategory.ReadError, null);
                 WriteError(er);
                 continue;
             }
         }
     }
 }
开发者ID:40a,项目名称:PowerShell,代码行数:54,代码来源:Eventlog.cs

示例12: RunAfterAllTests

        protected void RunAfterAllTests()
        {
            // TestHelper.StopWCFService();

            TestHelper.ClearLogs();

            // clear log entries in Application log
            EventLog log = new EventLog("Application", ".", "SourceLog4NET");
            log.Clear();
        }
开发者ID:bage,项目名称:Demo-Logging-Wrapper,代码行数:10,代码来源:Demo.cs

示例13: RunAfterAllTests

        protected void RunAfterAllTests()
        {
            TestHelper.ClearLogs();

            // clear log entries in Application log
            EventLog log = new EventLog(APPLICATION, MACHINE_NAME, SOURCE);
            log.Clear();
        }
开发者ID:bage,项目名称:Demo-Logging-Wrapper,代码行数:8,代码来源:Log4NETImplUnitTest.cs

示例14: button2_Click

 private void button2_Click(object sender, EventArgs e)
 {
     EventLog log = new EventLog("Application", ".");
     log.Clear();
     MessageBox.Show("OK");
 }
开发者ID:henrydem,项目名称:yongfa365doc,代码行数:6,代码来源:MSSQL.cs

示例15: LogClear

        /// <summary>
        /// Clear the event window viewer for SpringCard input
        /// </summary>
        private static void LogClear()
        {
            lock (locker)
            {
                try
                {
                    if (eventLog != null)
                    {
                        eventLog.Clear();

                        var eventLog1 = new EventLog("SpringCard", System.Environment.MachineName, "scCcidNetworkSvc");
                        eventLog1.Clear();
                    }
                }
                catch
                {

                }

            }
        }
开发者ID:springcard,项目名称:springcard.iwm2.sdk,代码行数:24,代码来源:logger.cs


注:本文中的System.Diagnostics.EventLog.Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。