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


C# EventLog.ModifyOverflowPolicy方法代码示例

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


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

示例1: LogManager

        private LogManager()
        {
            LogSection customSection = ConfigurationManager.GetSection("LogSection") as LogSection;
            if (customSection == null)
                customSection = new LogSection();

            try
            {
                this.excludeFlags = customSection.Exclude;

                string source = customSection.SourceName;
                string logName = customSection.LogName;

                myEventLog = new EventLog();
                myEventLog.Log = logName;
                myEventLog.Source = source;

                if( EventLog.SourceExists( source ) )
                    EventLog.DeleteEventSource( source );

                if( !System.Diagnostics.EventLog.SourceExists( source ) )
                    System.Diagnostics.EventLog.CreateEventSource( source, logName );

                if( myEventLog.OverflowAction != OverflowAction.OverwriteAsNeeded )
                    myEventLog.ModifyOverflowPolicy( OverflowAction.OverwriteAsNeeded, 0 );
            }
            catch( Exception ex )
            {
                Trace.TraceError( ex.Message + " at " + ex.Source );
            }
        }
开发者ID:plamikcho,项目名称:xbrlpoc,代码行数:31,代码来源:LogManager.cs

示例2: Logger

        static Logger()
        {
            TraceSwitch ts = new TraceSwitch("TraceLevelSwitch", "Determines the tracing level to log/display");
            TraceLevel = ts.Level;

            if (!EventLog.Exists("CSGO"))
            {
                EventLog.CreateEventSource(LOG_SOURCE, LOG_NAME);
            }

            try
            {
                _eventLog = new EventLog();
                _eventLog.Source = LOG_SOURCE;
                _eventLog.Log = LOG_NAME;
            }
            catch { }
            try
            {
                _eventLog.MaximumKilobytes = 200 * 1024;
                _eventLog.ModifyOverflowPolicy(OverflowAction.OverwriteAsNeeded, 0);
            }
            catch
            {
            }
            Trace.Listeners.Clear();
            Trace.Listeners.Add(new EventLogTraceListener(_eventLog)); // writes to EventLog
            Trace.Listeners.Add(new ConsoleTraceListener(true)); // writes to Console window
            Trace.Listeners.Add(new DefaultTraceListener()); // writes to Output window
        }
开发者ID:odinhaus,项目名称:Suffuz,代码行数:30,代码来源:Logger.cs

示例3: CreateLog

        public static EventLog CreateLog(string logSource, string logName)
        {
            try
            {
                if (!EventLog.Exists(logName))
                {
                    EventLog.CreateEventSource(logSource, logName);
                }

                EventLog eventLog = new EventLog(logName);
                eventLog.Source = logSource;
                try
                {
                    eventLog.ModifyOverflowPolicy(OverflowAction.OverwriteAsNeeded, 7);
                }
                catch (Exception ex)
                {
                    OnModifyOverFlowException(ex);
                }

                return eventLog;
            }
            catch (Exception ex)
            {
                OnCreateLogException(ex);
                return null;
            }
        }
开发者ID:BryanApellanes,项目名称:Naizari,代码行数:28,代码来源:WindowsLogger.cs

示例4: GetLog

        private static EventLog GetLog(string logSource, string logName)
        {
            if (!EventLog.Exists(logName))
            {
                EventLog.CreateEventSource(logSource, logName);
            }

            EventLog eventLog = new EventLog(logName);
            eventLog.Source = logSource;
            eventLog.ModifyOverflowPolicy(OverflowAction.OverwriteAsNeeded, 7);

            return eventLog;
        }
开发者ID:BryanApellanes,项目名称:Naizari,代码行数:13,代码来源:WindowsLogger.cs

示例5: ModifyOverflowPolicy

 public static void ModifyOverflowPolicy(string logSource, string logName, OverflowAction action, int retentionDays)
 {
     try
     {
         EventLog eventLog = new EventLog(logName);
         eventLog.Source = logSource;
         eventLog.ModifyOverflowPolicy(action, retentionDays);
     }
     catch (Exception ex)
     {
         OnModifyOverFlowException(ex);
     }
 }
开发者ID:BryanApellanes,项目名称:Naizari,代码行数:13,代码来源:WindowsLogger.cs

示例6: ReportBuilderManager

        protected ReportBuilderManager()
        {
            myEventLog = new EventLog();
            if (!System.Diagnostics.EventLog.SourceExists("ReportProcessor"))
            {
                System.Diagnostics.EventLog.CreateEventSource(
                   "ReportProcessor", "ReportBuilder");
            }
            myEventLog.Source = "ReportProcessor";
            myEventLog.Log = "ReportBuilder";

            if (myEventLog.OverflowAction != OverflowAction.OverwriteAsNeeded)
            {
                myEventLog.ModifyOverflowPolicy(OverflowAction.OverwriteAsNeeded, 0);
            }
        }
开发者ID:plamikcho,项目名称:xbrlpoc,代码行数:16,代码来源:ReportBuilderManager.cs

示例7: Init

 /// <summary>
 /// Метод инициализации журнала событий Windows.
 /// </summary>
 public static void Init()
 {
     // Иницируем журнал событий Windows
     try
     {
         // Если не существует windows лога службы, то создаем его и назначаем по-умолчанию для записи
         if (!EventLog.SourceExists("SmartHouseService"))
             EventLog.CreateEventSource("SmartHouseService", "SmartHouseServiceLog");
         // Иницируем журнал событий Windows
         _log = new EventLog();
         _log.Source = "SmartHouseService";
         _log.Log = "SmartHouseServiceLog";
         _log.ModifyOverflowPolicy(OverflowAction.OverwriteAsNeeded, 30);
     }
     catch (Exception)
     {
         if (_log != null)
             _log.Dispose();
         _log = null;
     }
 }
开发者ID:Brabys2012,项目名称:SmartHouse,代码行数:24,代码来源:WinLog.cs

示例8: InitWindowsEventLog

        private void InitWindowsEventLog()
        {
            if (this._windowsLogInitialized)
                return;

            if (!InitWindowsEventSource(Const.DEFAULT_APPLICATION_NAME, Const.WINDOWS_LOG_NAME))
                return;

            // Modification des paramètres du journal d'évènement
            if (EventLog.Exists(Const.WINDOWS_LOG_NAME))
            {
                EventLog a = new EventLog(Const.WINDOWS_LOG_NAME);
                if (a.OverflowAction != OverflowAction.OverwriteAsNeeded)
                {
                    a.ModifyOverflowPolicy(OverflowAction.OverwriteAsNeeded, 7);
                }

                if (a.MaximumKilobytes < 2048)
                {
                    a.MaximumKilobytes = 2048;
                }
            }

            this._windowsLogInitialized = true;
        }
开发者ID:ThomasGille,项目名称:Agence-immobili-re,代码行数:25,代码来源:Log.cs

示例9: Create

		public void Create()
		{
			string builtInSourceName = string.Concat(_logName, "Instrumentation");
			bool sourcesContainedBuildIn = false;

			// create sources
			foreach (string source in _sources)
			{
				CreateSource(source);
				if (source == builtInSourceName)
					sourcesContainedBuildIn = true;
			}

			if (!sourcesContainedBuildIn)
			{
				CreateSource(builtInSourceName);
			}

			using (EventLog eventLog = new EventLog(_logName, _machineName, builtInSourceName))
			{
				eventLog.ModifyOverflowPolicy(OverflowAction.OverwriteAsNeeded, 14);
				eventLog.MaximumKilobytes = _logSizeInMegaBytes * 1024;
				eventLog.WriteEntry("Log created.", EventLogEntryType.Information);
				eventLog.Dispose();
			}
		}
开发者ID:maxpavlov,项目名称:FlexNet,代码行数:26,代码来源:EventLogDeployer.cs

示例10: SetupEventLogTraceListener

 private static void SetupEventLogTraceListener()
 {
     if (!EventLog.SourceExists(eventLogSource))
     {
         EventLog.CreateEventSource(eventLogSource, eventLogName);
     }
     myEventLog = new EventLog();
     myEventLog.Source = eventLogSource;
     myEventLogTraceListener = new EventLogTraceListener(myEventLog);
     if (myEventLog.OverflowAction != OverflowAction.OverwriteAsNeeded)
     {
         myEventLog.ModifyOverflowPolicy(OverflowAction.OverwriteAsNeeded, 1);
     }
     Trace.Listeners.Add(myEventLogTraceListener);
 }
开发者ID:OptecInc,项目名称:FocusLynx-Software-PC,代码行数:15,代码来源:EventLogger.cs

示例11: BeginProcessing

		protected override void BeginProcessing()
		{
			string str;
			string[] strArrays = this._computerName;
			for (int i = 0; i < (int)strArrays.Length; i++)
			{
				string str1 = strArrays[i];
				if (str1.Equals("localhost", StringComparison.CurrentCultureIgnoreCase) || str1.Equals(".", StringComparison.OrdinalIgnoreCase))
				{
					str = "localhost";
				}
				else
				{
					str = str1;
				}
				string[] strArrays1 = this._logName;
				for (int j = 0; j < (int)strArrays1.Length; j++)
				{
					string str2 = strArrays1[j];
					try
					{
						if (EventLog.Exists(str2, str1))
						{
							if (base.ShouldProcess(StringUtil.Format(EventlogResources.LimitEventLogWarning, str2, str)))
							{
								EventLog eventLog = new EventLog(str2, str1);
								int minimumRetentionDays = eventLog.MinimumRetentionDays;
								OverflowAction overflowAction = eventLog.OverflowAction;
								if (!this.retentionSpecified || !this.overflowSpecified)
								{
									if (!this.retentionSpecified || this.overflowSpecified)
									{
										if (!this.retentionSpecified && this.overflowSpecified)
										{
											eventLog.ModifyOverflowPolicy(this._overflowaction, minimumRetentionDays);
										}
									}
									else
									{
										if (overflowAction.CompareTo(OverflowAction.OverwriteOlder) != 0)
										{
											ErrorRecord errorRecord = new ErrorRecord(new InvalidOperationException(StringUtil.Format(EventlogResources.InvalidOverflowAction, new object[0])), null, ErrorCategory.InvalidOperation, null);
											base.WriteError(errorRecord);
											goto Label0;
										}
										else
										{
											eventLog.ModifyOverflowPolicy(overflowAction, this._retention);
										}
									}
								}
								else
								{
									if (this._overflowaction.CompareTo(OverflowAction.OverwriteOlder) != 0)
									{
										ErrorRecord errorRecord1 = new ErrorRecord(new InvalidOperationException(StringUtil.Format(EventlogResources.InvalidOverflowAction, new object[0])), null, ErrorCategory.InvalidOperation, null);
										base.WriteError(errorRecord1);
										goto Label0;
									}
									else
									{
										eventLog.ModifyOverflowPolicy(this._overflowaction, this._retention);
									}
								}
								if (this.maxkbSpecified)
								{
									int num = 0x400;
									this._maximumKilobytes = this._maximumKilobytes / (long)num;
									eventLog.MaximumKilobytes = this._maximumKilobytes;
								}
							}
						}
						else
						{
							ErrorRecord errorRecord2 = new ErrorRecord(new InvalidOperationException(StringUtil.Format(EventlogResources.LogDoesNotExist, str2, str)), null, ErrorCategory.InvalidOperation, null);
							base.WriteError(errorRecord2);
						}
					}
					catch (InvalidOperationException invalidOperationException1)
					{
						InvalidOperationException invalidOperationException = invalidOperationException1;
						this.WriteNonTerminatingError(invalidOperationException, EventlogResources.PermissionDenied, "PermissionDenied", ErrorCategory.PermissionDenied, str2, str);
					}
					catch (IOException oException1)
					{
						IOException oException = oException1;
						this.WriteNonTerminatingError(oException, EventlogResources.PathDoesNotExist, "PathDoesNotExist", ErrorCategory.InvalidOperation, null, str);
					}
					catch (ArgumentOutOfRangeException argumentOutOfRangeException1)
					{
						ArgumentOutOfRangeException argumentOutOfRangeException = argumentOutOfRangeException1;
						if (this.retentionSpecified || this.maxkbSpecified)
						{
							this.WriteNonTerminatingError(argumentOutOfRangeException, EventlogResources.ValueOutofRange, "ValueOutofRange", ErrorCategory.InvalidData, null, null);
						}
						else
						{
							this.WriteNonTerminatingError(argumentOutOfRangeException, EventlogResources.InvalidArgument, "InvalidArgument", ErrorCategory.InvalidData, null, null);
						}
					}
//.........这里部分代码省略.........
开发者ID:nickchal,项目名称:pash,代码行数:101,代码来源:LimitEventLogCommand.cs

示例12: BeginProcessing

 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 logname in LogName)
         {
             try
             {
                 if (!EventLog.Exists(logname, compname))
                 {
                     ErrorRecord er = new ErrorRecord(new InvalidOperationException(StringUtil.Format(EventlogResources.LogDoesNotExist, logname, computer)), null, ErrorCategory.InvalidOperation, null);
                     WriteError(er);
                     continue;
                 }
                 else
                 {
                     if (!ShouldProcess(StringUtil.Format(EventlogResources.LimitEventLogWarning, logname, computer)))
                     {
                         continue;
                     }
                     else
                     {
                         EventLog newLog = new EventLog(logname, compname);
                         int _minRetention = newLog.MinimumRetentionDays;
                         System.Diagnostics.OverflowAction _newFlowAction = newLog.OverflowAction;
                         if (_retentionSpecified && _overflowSpecified)
                         {
                             if (_overflowaction.CompareTo(System.Diagnostics.OverflowAction.OverwriteOlder) == 0)
                             {
                                 newLog.ModifyOverflowPolicy(_overflowaction, _retention);
                             }
                             else
                             {
                                 ErrorRecord er = new ErrorRecord(new InvalidOperationException(StringUtil.Format(EventlogResources.InvalidOverflowAction)), null, ErrorCategory.InvalidOperation, null);
                                 WriteError(er);
                                 continue;
                             }
                         }
                         else if (_retentionSpecified && !_overflowSpecified)
                         {
                             if (_newFlowAction.CompareTo(System.Diagnostics.OverflowAction.OverwriteOlder) == 0)
                             {
                                 newLog.ModifyOverflowPolicy(_newFlowAction, _retention);
                             }
                             else
                             {
                                 ErrorRecord er = new ErrorRecord(new InvalidOperationException(StringUtil.Format(EventlogResources.InvalidOverflowAction)), null, ErrorCategory.InvalidOperation, null);
                                 WriteError(er);
                                 continue;
                             }
                         }
                         else if (!_retentionSpecified && _overflowSpecified)
                         {
                             newLog.ModifyOverflowPolicy(_overflowaction, _minRetention);
                         }
                         if (_maxkbSpecified)
                         {
                             int kiloByte = 1024;
                             _maximumKilobytes = _maximumKilobytes / kiloByte;
                             newLog.MaximumKilobytes = _maximumKilobytes;
                         }
                     }
                 }
             }
             catch (InvalidOperationException ex)
             {
                 WriteNonTerminatingError(ex, EventlogResources.PermissionDenied, "PermissionDenied", ErrorCategory.PermissionDenied, logname, computer);
                 continue;
             }
             catch (System.IO.IOException ex)
             {
                 WriteNonTerminatingError(ex, EventlogResources.PathDoesNotExist, "PathDoesNotExist", ErrorCategory.InvalidOperation, null, computer);
                 continue;
             }
             catch (ArgumentOutOfRangeException ex)
             {
                 if (!_retentionSpecified && !_maxkbSpecified)
                 {
                     WriteNonTerminatingError(ex, EventlogResources.InvalidArgument, "InvalidArgument", ErrorCategory.InvalidData, null, null);
                 }
                 else
                 {
                     WriteNonTerminatingError(ex, EventlogResources.ValueOutofRange, "ValueOutofRange", ErrorCategory.InvalidData, null, null);
                 }
                 continue;
             }
         }
     }
 }
开发者ID:40a,项目名称:PowerShell,代码行数:98,代码来源:Eventlog.cs

示例13: RivetCustomEventLogSource

        /// <summary>
        /// Creates a new AucentCustomEventLogSource.  Pass in your TaxonomyFileName (without extension) to create your log.
        /// </summary>
        public RivetCustomEventLogSource(string EventLogTitle, string EventSourceName, string TargetMachineName)
        {
            try
            {
                if (TargetMachineName == string.Empty || TargetMachineName == null)
                    TargetMachineName = Environment.MachineName;

                eventLogName = EventLogTitle;

                if(EventLog.SourceExists(EventSourceName, TargetMachineName))
                    // Are we dealing with the same log for the source?
                    if (EventLogTitle.Trim() != EventLog.LogNameFromSourceName(EventSourceName, TargetMachineName).Trim())
                        EventLog.DeleteEventSource(EventSourceName, TargetMachineName);

                // Create EventLog if needed
                if(!EventLog.Exists(EventLogTitle, TargetMachineName))
                {
                    if (EventLog.SourceExists(EventLogTitle, TargetMachineName))
                    {
                        // If an event source exists in the name of the EventLog, we should remove the
                        // event source
                        try
                        {
                            EventLog.DeleteEventSource(EventLogTitle, TargetMachineName);
                        }
                        catch
                        {
                            // If we had an issue with deleting the EventSource because it matches some EventLog title,
                            // we have no choice but to remove the EventLog alltogether!
                            EventLog.Delete(EventLogTitle, TargetMachineName);
                        }
                    }
                    EventSourceCreationData dataSource = new EventSourceCreationData(EventSourceName, EventLogTitle);
                    dataSource.MachineName = TargetMachineName;
                    EventLog.CreateEventSource(dataSource);
                }
                // Create the event source if it does not exist
                if (!EventLog.SourceExists(EventSourceName, TargetMachineName))
                {
                    EventSourceCreationData dataSource = new EventSourceCreationData(EventSourceName, EventLogTitle);
                    dataSource.MachineName = TargetMachineName;
                    EventLog.CreateEventSource(dataSource);
                }
                if (!eventLogsUpdated.Contains(EventLogTitle) )
                {
                    EventLog myLog = new EventLog(EventLogTitle, TargetMachineName);
                    if (myLog.OverflowAction != OverflowAction.OverwriteAsNeeded)
                    {
                        myLog.ModifyOverflowPolicy(OverflowAction.OverwriteAsNeeded, 0);
                    }

                    eventLogsUpdated.Add(EventLogTitle);
                }

            }
            catch(System.Exception ex)
            {
                string msg = ex.Message;
            }
        }
开发者ID:plamikcho,项目名称:xbrlpoc,代码行数:63,代码来源:AucentCustomEventLogSource.cs

示例14: SetOptionsIfNeed

 static void SetOptionsIfNeed(EventLog log)
 {
     if (log.OverflowAction != OverflowAction.OverwriteAsNeeded)
     {
         log.ModifyOverflowPolicy(OverflowAction.OverwriteAsNeeded, 1);
         log.MaximumKilobytes = 512000;
     }
 }
开发者ID:Minatron,项目名称:Minatron,代码行数:8,代码来源:EventLogger.cs

示例15: InitLog

 // ------- Инициализация --------
 protected void InitLog()
 {
     if (!EventLog.Exists(myLog) || !EventLog.SourceExists(mySource))
     {
         EventLog.CreateEventSource(mySource, myLog);
         EventLog log = new EventLog(myLog);
         log.MaximumKilobytes = maximumKilobytes;
         log.ModifyOverflowPolicy(OverflowAction.OverwriteOlder, retentionDay);
     }
 }
开发者ID:slawer,项目名称:service,代码行数:11,代码来源:Journal.cs


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