• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Diagnostics.EventSourceCreationData类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Constructor1

		public void Constructor1 ()
		{
			EventSourceCreationData crd;

			crd = new EventSourceCreationData (null, null);
			Assert.AreEqual (0, crd.CategoryCount, "#A1");
			Assert.IsNull (crd.CategoryResourceFile, "#A2");
			Assert.IsNull (crd.LogName, "#A3");
			Assert.IsNotNull (crd.MachineName, "#A4");
			Assert.AreEqual (".", crd.MachineName, "#A5");
			Assert.IsNull (crd.MessageResourceFile, "#A6");
			Assert.IsNull (crd.ParameterResourceFile, "#A7");
			Assert.IsNull (crd.Source, "#A8");

			crd = new EventSourceCreationData ("src", null);
			Assert.AreEqual (0, crd.CategoryCount, "#B1");
			Assert.IsNull (crd.CategoryResourceFile, "#B2");
			Assert.IsNull (crd.LogName, "#B3");
			Assert.IsNotNull (crd.MachineName, "#B4");
			Assert.AreEqual (".", crd.MachineName, "#B5");
			Assert.IsNull (crd.MessageResourceFile, "#B6");
			Assert.IsNull (crd.ParameterResourceFile, "#B7");
			Assert.IsNotNull (crd.Source, "#B8");
			Assert.AreEqual ("src", crd.Source, "#B9");

			crd = new EventSourceCreationData (null, "log");
			Assert.AreEqual (0, crd.CategoryCount, "#C1");
			Assert.IsNull (crd.CategoryResourceFile, "#C2");
			Assert.IsNotNull (crd.LogName, "#C3");
			Assert.AreEqual ("log", crd.LogName, "#C4");
			Assert.IsNotNull (crd.MachineName, "#C5");
			Assert.AreEqual (".", crd.MachineName, "#C6");
			Assert.IsNull (crd.MessageResourceFile, "#C7");
			Assert.IsNull (crd.ParameterResourceFile, "#C8");
			Assert.IsNull (crd.Source, "#C9");

			crd = new EventSourceCreationData ("src", "log");
			Assert.AreEqual (0, crd.CategoryCount, "#C1");
			Assert.IsNull (crd.CategoryResourceFile, "#C2");
			Assert.IsNotNull (crd.LogName, "#C3");
			Assert.AreEqual ("log", crd.LogName, "#C4");
			Assert.IsNotNull (crd.MachineName, "#C5");
			Assert.AreEqual (".", crd.MachineName, "#C6");
			Assert.IsNull (crd.MessageResourceFile, "#C7");
			Assert.IsNull (crd.ParameterResourceFile, "#C8");
			Assert.IsNotNull (crd.Source, "#C9");
			Assert.AreEqual ("src", crd.Source, "#C10");
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:48,代码来源:EventSourceCreationDataTest.cs


示例17: GetEventLog

        /// <summary>
        /// 해당 EventLog를 반환한다. Event Source가 없다면 생성한다.
        /// </summary>
        /// <param name="logName">로그 이름</param>
        /// <param name="source">엔트리 소스</param>
        /// <param name="machineName">로그가 있는 컴퓨터</param>
        /// <returns></returns>
        public static EventLog GetEventLog(string logName, string source, string machineName) {
            logName.ShouldNotBeWhiteSpace("logName");

            if(EventLog.SourceExists(source, machineName) == false) {
                var sourceData = new EventSourceCreationData(source, logName)
                                 {
                                     MachineName = machineName
                                 };
                EventLog.CreateEventSource(sourceData);
            }

            return new EventLog(logName, machineName, source)
                   {
                       EnableRaisingEvents = true
                   };
        }
开发者ID:debop,项目名称:NFramework,代码行数:23,代码来源:EventLogTool.cs


示例18: Main

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {

            if (!EventLog.SourceExists("SmokeSignal"))
            {
                EventSourceCreationData cd = new EventSourceCreationData("SmokeSignal", "Application");

                EventLog.CreateEventSource(cd);
            }
 
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[] 
			{ 
				new SmokeSignal() 
			};
            ServiceBase.Run(ServicesToRun);
        }
开发者ID:potrebic,项目名称:smokesignal.net,代码行数:20,代码来源:Program.cs


示例19: EventLogListener

        /// <summary>
        /// Initializes a new instance of the <see cref="EventLogListener"/> class.
        /// </summary>
        public EventLogListener()
        {
            var assembly = AssemblyHelper.GetEntryAssembly();

            Source = assembly.Title();
            LogName = "Application";
            MachineName = Dns.GetHostName();

            var sourceData = new EventSourceCreationData(Source, LogName)
            {
                MachineName = MachineName
            };

            if (!EventLog.SourceExists(Source, MachineName))
            {
                EventLog.CreateEventSource(sourceData);
            }
        }
开发者ID:jensweller,项目名称:Catel,代码行数:21,代码来源:EventLogListener.cs


示例20: CreateEventLog

    /// <summary>
    /// 创建事件日志
    /// </summary>
    /// <param name="machine">主机名称</param>
    /// <param name="logName">日志名称</param>
    /// <param name="source">事件源描述</param>
    /// <returns>事件日志</returns>
    public static EventLog CreateEventLog(string machine, string logName, string source)
    {
      EventLog log = GetEventLog(machine, logName);

      if (log == null)
      {
        EventSourceCreationData data = new EventSourceCreationData(source, logName);
        EventLog.CreateEventSource(data);
        log = GetEventLog(machine, logName);
        log.Source = source;
      }
      else
      {
        log.Source = source;
      }

      return log;
    }
开发者ID:sclcwwl,项目名称:Gimela,代码行数:25,代码来源:EventLogManager.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Diagnostics.LogSwitch类代码示例发布时间:2022-05-26
下一篇:
C# Diagnostics.EventLogPermission类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap