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


C# Diagnostics.EventSourceCreationData类代码示例

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


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

示例1: CreateEventSource

		public override void CreateEventSource (EventSourceCreationData sourceData)
		{
			// construct path for storing log entries
			string logDir = FindLogStore (sourceData.LogName);
			// create event log store (if necessary), and modify access
			// permissions (unix only)
			if (!Directory.Exists (logDir)) {
				// ensure the log name is valid for customer logs
				ValidateCustomerLogName (sourceData.LogName, sourceData.MachineName);

				Directory.CreateDirectory (logDir);
				// MS does not allow an event source to be named after an already
				// existing event log. To speed up checking whether a given event
				// source already exists (either as a event source or event log)
				// we create an event source directory named after the event log.
				// This matches what MS does with the registry-based registration.
				Directory.CreateDirectory (Path.Combine (logDir, sourceData.LogName));
				if (RunningOnUnix) {
					ModifyAccessPermissions (logDir, "777");
					ModifyAccessPermissions (logDir, "+t");
				}
			}
			// create directory for event source, so we can check if the event
			// source already exists
			string sourceDir = Path.Combine (logDir, sourceData.Source);
			Directory.CreateDirectory (sourceDir);
		}
开发者ID:Xipas,项目名称:Symplified.Auth,代码行数:27,代码来源:LocalFileEventLog.cs

示例2: Run

        static void Run()
        {
            string messageFile = "message.txt";

            string myLogName;
            string sourceName = "SampleApplicationSource";

            // Create the event source if it does not exist.
            if (!EventLog.SourceExists(sourceName))
            {
                // Create a new event source for the custom event log named "myNewLog".
                myLogName = "myNewLog";
                EventSourceCreationData mySourceData = new EventSourceCreationData(sourceName, myLogName);

                // Set the message resource file that the event source references.
                // All event resource identifiers correspond to test in this file.
                if (!System.IO.File.Exists(messageFile))
                {
                    Console.WriteLine("Input message resource file does not exist - {0}", messageFile);
                    messageFile = "";
                }
                else
                {
                    // Set the specified file as the resource file for message text,
                    //   category text, and message parameter strings.
                    mySourceData.MessageResourceFile = messageFile;
                    mySourceData.CategoryResourceFile = messageFile;
                    mySourceData.CategoryCount = CategoryCount;
                }
            }
        }
开发者ID:oblivious,项目名称:Oblivious,代码行数:31,代码来源:CreateEventSourceSample1.cs

示例3: CreateEventLog

        public static EventLog CreateEventLog(string name)
        {
            string eventLogName = string.Empty;

            try
            {
                eventLogName = HostingEnvironment.ApplicationVirtualPath.Trim("/".ToCharArray());
                if (string.IsNullOrEmpty(eventLogName)) eventLogName = HostingEnvironment.SiteName;
            }
            catch
            {
                // not running under a hosted environment
            }

            if (string.IsNullOrEmpty(eventLogName)) eventLogName = name;
            if (string.IsNullOrEmpty(eventLogName)) eventLogName = "SnCore";

            if (! EventLog.SourceExists(eventLogName))
            {
                EventSourceCreationData data = new EventSourceCreationData(eventLogName, "Application");
                EventLog.CreateEventSource(data);
            }

            EventLog result  = new EventLog();
            result.Log = "Application";
            result.Source = eventLogName;
            return result;
        }
开发者ID:dblock,项目名称:sncore,代码行数:28,代码来源:HostedApplication.cs

示例4: createEventLogSource_Click

        protected void createEventLogSource_Click(object sender, EventArgs e)
        {
            try
            {
                EventSourceCreationData creationData = new EventSourceCreationData(_Source, _LogName);
                if (EventLog.Exists(_LogName, ".") == false)
                {
                    //source未在该服务器上注册过
                    EventLog.CreateEventSource(creationData);
                    createMessage.InnerText = "没有Log,创建Log和Source";
                }
                else
                {
                    if (EventLog.SourceExists(_Source))
                    {
                        string originalLogName = EventLog.LogNameFromSourceName(_Source, ".");

                        //source注册的日志名称和指定的logName不一致,且不等于source自身
                        //(事件日志源“System”等于日志名称,不能删除。[System.InvalidOperationException])
                        if (string.Compare(_LogName, originalLogName, true) != 0 && string.Compare(_Source, originalLogName, true) != 0)
                        {
                            //删除现有的关联重新注册
                            EventLog.DeleteEventSource(_Source, ".");
                            EventLog.CreateEventSource(creationData);

                            createMessage.InnerText = "已经有Log,重新创建Log和Source";
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                createMessage.InnerText = ex.Message;
            }
        }
开发者ID:jerryshi2007,项目名称:AK47Source,代码行数:35,代码来源:EventLogSourceTest.aspx.cs

示例5: Init

        private bool Init()
        {
            try
            {
                if (!EventLog.SourceExists(_eventSourceName))
                {
                    var eventSourceData = new EventSourceCreationData(_eventSourceName, _logName);
                    EventLog.CreateEventSource(eventSourceData);
                }

                _DBConnStr = ConfigurationManager.AppSettings["DBConnStr"].Trim();
                _MQServerUri = ConfigurationManager.AppSettings["MQServerUri"].Trim();
                _QueueName = ConfigurationManager.AppSettings["QueueName"].Trim();
                _Interval = int.Parse(ConfigurationManager.AppSettings["Interval"].Trim());
                _KpiInterval = int.Parse(ConfigurationManager.AppSettings["KpiInterval"].Trim());

                _Timer = new Timer() { Interval = _Interval, AutoReset = true, Enabled = true };
                _Timer.Elapsed += new ElapsedEventHandler(SendKpi);

                Log("Init completed.");
                return true;
            }
            catch(Exception ex)
            {
                LogError(ex.Message);
                return false;
            }
        }
开发者ID:shaweiguo,项目名称:IMSKPISender,代码行数:28,代码来源:IMSKPISender.cs

示例6: CreateEventSource

		public override void CreateEventSource (EventSourceCreationData sourceData)
		{
			using (RegistryKey eventLogKey = GetEventLogKey (sourceData.MachineName, true)) {
				if (eventLogKey == null)
					throw new InvalidOperationException ("EventLog registry key is missing.");

				bool logKeyCreated = false;
				RegistryKey logKey = null;
				try {
					logKey = eventLogKey.OpenSubKey (sourceData.LogName, true);
					if (logKey == null) {
						ValidateCustomerLogName (sourceData.LogName, 
							sourceData.MachineName);

						logKey = eventLogKey.CreateSubKey (sourceData.LogName);
						logKey.SetValue ("Sources", new string [] { sourceData.LogName,
							sourceData.Source });
						UpdateLogRegistry (logKey);

						using (RegistryKey sourceKey = logKey.CreateSubKey (sourceData.LogName)) {
							UpdateSourceRegistry (sourceKey, sourceData);
						}

						logKeyCreated = true;
					}

					if (sourceData.LogName != sourceData.Source) {
						if (!logKeyCreated) {
							string [] sources = (string []) logKey.GetValue ("Sources");
							if (sources == null) {
								logKey.SetValue ("Sources", new string [] { sourceData.LogName,
									sourceData.Source });
							} else {
								bool found = false;
								for (int i = 0; i < sources.Length; i++) {
									if (sources [i] == sourceData.Source) {
										found = true;
										break;
									}
								}
								if (!found) {
									string [] newSources = new string [sources.Length + 1];
									Array.Copy (sources, 0, newSources, 0, sources.Length);
									newSources [sources.Length] = sourceData.Source;
									logKey.SetValue ("Sources", newSources);
								}
							}
						}
						using (RegistryKey sourceKey = logKey.CreateSubKey (sourceData.Source)) {
							UpdateSourceRegistry (sourceKey, sourceData);
						}
					}
				} finally {
					if (logKey != null)
						logKey.Close ();
				}
			}
		}
开发者ID:sushihangover,项目名称:playscript,代码行数:58,代码来源:Win32EventLog.cs

示例7: Application_Error

        protected void Application_Error(object sender, EventArgs e)
        {
            var objErr = Server.GetLastError().GetBaseException();
            var source = new EventSourceCreationData("ECO.Web", "Application");
            if (!EventLog.SourceExists(source.Source, source.MachineName))
                EventLog.CreateEventSource(source);

            EventLog.WriteEntry(source.Source, GetInnerMostException(objErr).Message);
        }
开发者ID:dotnet236,项目名称:dotnet236,代码行数:9,代码来源:Global.asax.cs

示例8: Install

        public override void Install(System.Collections.IDictionary stateSaver)
        {
            base.Install(stateSaver);

            if (!EventLog.SourceExists(eventSourceName, "."))
            {
                EventSourceCreationData eventLogData = new EventSourceCreationData(eventSourceName, "Application");
                eventLogData.MachineName = ".";
                EventLog.CreateEventSource(eventLogData);
            }
        }
开发者ID:andregasser,项目名称:Yabe,代码行数:11,代码来源:RegistryAction.cs

示例9: EventLogSink

        /// <summary>
        /// Construct a sink posting to the Windows event log, creating the specified <paramref name="source"/> if it does not exist.
        /// </summary>
        /// <param name="source">The source name by which the application is registered on the local computer. </param>
        /// <param name="logName">The name of the log the source's entries are written to. Possible values include Application, System, or a custom event log.</param>
        /// <param name="textFormatter">Supplies culture-specific formatting information, or null.</param>
        /// <param name="machineName">The name of the machine hosting the event log written to.</param>
        public EventLogSink(string source, string logName, ITextFormatter textFormatter, string machineName)
        {
            if (source == null) throw new ArgumentNullException("source");

            _textFormatter = textFormatter;
            _source = source;

            var sourceData = new EventSourceCreationData(source, logName) { MachineName = machineName };

            if (!System.Diagnostics.EventLog.SourceExists(source, machineName)) System.Diagnostics.EventLog.CreateEventSource(sourceData);
        }
开发者ID:Worthaboutapig,项目名称:serilog,代码行数:18,代码来源:EventLogSink.cs

示例10: DiagnosticsLogger

		/// <summary>
		///   Creates a logger based on <see cref = "EventLog" />.
		/// </summary>
		/// <param name = "logName"><see cref = "EventLog.Log" /></param>
		/// <param name = "machineName"><see cref = "EventLog.MachineName" /></param>
		/// <param name = "source"><see cref = "EventLog.Source" /></param>
		public DiagnosticsLogger(string logName, string machineName, string source)
		{
			// Create the source, if it does not already exist.
			if (!EventLog.SourceExists(source, machineName))
			{
				var eventSourceCreationData = new EventSourceCreationData(source, logName);
				eventSourceCreationData.MachineName = machineName;
				EventLog.CreateEventSource(eventSourceCreationData);
			}

			eventLog = new EventLog(logName, machineName, source);
		}
开发者ID:elevine,项目名称:Core,代码行数:18,代码来源:DiagnosticsLogger.cs

示例11: InsertarWarningEventLog

 public static void InsertarWarningEventLog(string strOrigen, System.Exception e)
 {
     // Verifico que en el EventLog exista el origen
     if (!EventLog.SourceExists(strOrigen, "."))
     {
         // Si el origen no existe en el EventLog, lo creo dentro del grupo de errores de Aplicacion
         EventSourceCreationData srcData = new EventSourceCreationData(strOrigen, "Application");
         EventLog.CreateEventSource(srcData);
     }
     // Escribo el registro del warning en el EventLog
     EventLog.WriteEntry(strOrigen, e.Source + "\n" + e.Message + "\n" + e.StackTrace, EventLogEntryType.Warning);
 }
开发者ID:giselleCZ,项目名称:edesoft,代码行数:12,代码来源:EventsLog.cs

示例12: InsertarInformacionEventLog

 public static void InsertarInformacionEventLog(string strOrigen, string strMensaje)
 {
     // Verifico que en el EventLog exista el orig
     if (!EventLog.SourceExists(strOrigen, "."))
     {
         // Si el origen no existe en el EventLog, lo creo dentro del grupo de errores de Aplicacion
         EventSourceCreationData srcData = new EventSourceCreationData(strOrigen, "Application");
         EventLog.CreateEventSource(srcData);
     }
     // Escribo el registro del warning en el EventLog
     EventLog.WriteEntry(strOrigen, strMensaje, EventLogEntryType.Information, 123);
 }
开发者ID:giselleCZ,项目名称:edesoft,代码行数:12,代码来源:EventsLog.cs

示例13: LogToEvent

        //// GET: api/Heroku
        //public string Get()
        //{
        //    LogToEvent("Entered Get", EventLogEntryType.Information);
        //    return "Get Successful";
        //}
        private void LogToEvent(string msg, EventLogEntryType errorType)
        {
            // create event source
            string strSource = "Wlocate";
            string instanceName = System.AppDomain.CurrentDomain.BaseDirectory;
            EventSourceCreationData evtSource = new EventSourceCreationData(strSource, strSource);
            if (!EventLog.SourceExists(strSource))
                EventLog.CreateEventSource(evtSource);

            // check error type
            string strLog = String.Format("{0}: {1}\r\n\"{2}\"", instanceName, strSource, msg);
            EventLog.WriteEntry(strSource, strLog, errorType);
        }
开发者ID:dantz15,项目名称:CodingChallenge-Dante,代码行数:19,代码来源:HerokuController.cs

示例14: EventLogger

		/// <summary>
		/// Initializes the logger by creating the necessary
		/// <see cref="EventLog"/> source.
		/// </summary>
		public EventLogger()
		{
			string source = ConfigurationSettings.Settings.ConnectionString;

			// Create the source, if it does not already exist.
			if (!EventLog.SourceExists(source, MACHINE_NAME))
			{
				EventSourceCreationData sourceData = new EventSourceCreationData(source, LOG_NAME);
				EventLog.CreateEventSource(sourceData);
			}

			_eventLog = new EventLog(LOG_NAME, MACHINE_NAME, source);
		}
开发者ID:cnporras,项目名称:wilsonormapper,代码行数:17,代码来源:EventLogger.cs

示例15: WriteToEventLog

        public static void WriteToEventLog(string msg, string source) {
            

            if (!EventLog.SourceExists(source)) { 
                EventSourceCreationData sourceData = new EventSourceCreationData(source, source);

                EventLog.CreateEventSource(sourceData);
            }

            EventLog log = new EventLog();
            log.Source = source;
            log.WriteEntry(msg);
        }
开发者ID:jansater,项目名称:TypeLess,代码行数:13,代码来源:SimpleLog.cs


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