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

C# Diagnostics.EventLog类代码示例

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

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



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

示例1: Process

      static public ImageProcessingResult Process(string imageName, IBinaryRepository binaryRepository)
      {
         var log = new EventLog("Application")
         {
            Source = "Tadmap"
         };

         log.WriteEntry("Processing image:" + imageName, EventLogEntryType.Information);

         Stream binary = binaryRepository.GetBinary(imageName);

         if (binary == null)
         {
            log.WriteEntry("No binary found:" + imageName, EventLogEntryType.Warning);
            return new ImageProcessingResult { Key = imageName, Result = ImageProcessingResult.ResultType.Failed }; // Image not available in the queue yet.
         }

         // If I have an image I should renew the message.

         IImageSet imageSet = new ImageSet1(imageName);

         int zoomLevels;
         int tileSize;
         imageSet.Create(binary, binaryRepository, out zoomLevels, out tileSize);
         log.WriteEntry("Processing finished.", EventLogEntryType.Information);

         return new ImageProcessingResult
         {
            Key = imageName,
            Result = ImageProcessingResult.ResultType.Complete,
            ZoomLevel = zoomLevels,
            TileSize = tileSize
         };
      }
开发者ID:trevorpower,项目名称:tadmap,代码行数:34,代码来源:ProcessImage.cs


示例2: WriteLog

        private static void WriteLog(TraceLevel level, String messageText)
        {
            try
            {
                EventLogEntryType LogEntryType;
                switch (level)
                {
                    case TraceLevel.Error:
                        LogEntryType = EventLogEntryType.Error;
                        break;
                    default:
                        LogEntryType = EventLogEntryType.Error;
                        break;
                }
                String LogName = "Application";
                if (!EventLog.SourceExists(LogName))
                {
                    EventLog.CreateEventSource(LogName, "BIZ");
                }

                EventLog eventLog = new EventLog(LogName, ".", LogName);//��־���ԵĻ���
                eventLog.WriteEntry(messageText, LogEntryType);
            }
            catch
            {
            }
        }
开发者ID:W8023Y2014,项目名称:jsion,代码行数:27,代码来源:ApplicationLog.cs


示例3: EventViewerLogger

        /// <summary>
        /// The constructor.
        /// </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.</param>
        public EventViewerLogger(string source, string logName)
        {
            // Sanitize
            if (string.IsNullOrWhiteSpace(source))
            {
                throw new ArgumentException("cannot be null, empty, or white space", "source");
            }
            if (string.IsNullOrWhiteSpace(logName))
            {
                throw new ArgumentException("cannot be null, empty, or white space", "logName");
            }

            // Attempt to ensure that the event log source exists
            try
            {
                if (!EventLog.SourceExists(source))
                {
                    EventLog.CreateEventSource(source, logName);
                }
            }
            catch (SecurityException)
            {
                // Ignore it...
            }

            // Initialize the event log for logging
            _eventLog = new EventLog
            {
                Source = source,
                Log = logName
            };
        }
开发者ID:Damian-Pumar,项目名称:dache,代码行数:37,代码来源:EventViewerLogger.cs


示例4: CanGetCountFromEventLog

 public void CanGetCountFromEventLog()
 {
     using (EventLog eventLog = new EventLog("Application"))
     {
         Assert.IsTrue(eventLog.Entries.Count > 0);
     }
 }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:7,代码来源:EventLogExplorationFixture.cs


示例5: AddWindowsEventLog

        private void AddWindowsEventLog(string message, EventLogEntryType logType = EventLogEntryType.Information, string moduleName = "", int codeErreur = 0, bool fromFileLogEvent = false)
        {
            EventLog evLog = new EventLog(Const.WINDOWS_LOG_NAME);

            message = string.Concat(message, "\r\n", "Module : ", moduleName);
            evLog.Source = Const.DEFAULT_APPLICATION_NAME;

            InitWindowsEventLog();

            try
            {
                evLog.WriteEntry(message, logType, codeErreur);
            }
            catch (Exception ex)
            {
                if (!fromFileLogEvent)
                {
                    AddFileEventLog("Impossible d'écrire dans le journal de log " + Log.Const.WINDOWS_LOG_NAME + ".\r\nLe journal doit être créé préalablement avec un compte Administrateur.\r\nMessage :\r\n" + message + "\r\nException : " + ex.Message, logType, moduleName, codeErreur, true);
                }
            }
            finally
            {
                evLog.Close();
            }
        }
开发者ID:ThomasGille,项目名称:Agence-immobili-re,代码行数:25,代码来源:Log.cs


示例6: OnStart

        protected override void OnStart(string[] args)
        {
            if (!EventLog.SourceExists("SSISIncomingDirectoryWatcher", "."))
            {
                EventLog.CreateEventSource("SSISIncomingDirectoryWatcher", "Application");
            }

            Lg = new EventLog("Application", ".", "SSISIncomingDirectoryWatcher");
            Lg.WriteEntry("Service started at " + DateTime.Now, EventLogEntryType.Information);

            try
            {

                tw = File.CreateText(logFilePath);
                tw.WriteLine("Service started at {0}", DateTime.Now);
                readInConfigValues();
                Watcher = new FileSystemWatcher();
                Watcher.Path = dirToWatch;
                Watcher.IncludeSubdirectories = false;
                Watcher.Created += new FileSystemEventHandler(watcherChange);
                Watcher.EnableRaisingEvents = true;
            }
            catch (Exception ex)
            {
                Lg.WriteEntry(ex.Message, EventLogEntryType.Error);
            }
            finally
            {
                tw.Close();
            }
        }
开发者ID:johnkabler,项目名称:Small-Projects-and-Utils,代码行数:31,代码来源:Service1.cs


示例7: Window_Loaded

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            EventLog log = new EventLog("EventLog Log");
            log.Source = "LoggingApp";            
            log.WriteEntry("LoggingApp Started", EventLogEntryType.Information, 1001);

        }
开发者ID:Rafael-Miceli,项目名称:ProjectStudiesCert70-536,代码行数:7,代码来源:MainWindow.xaml.cs


示例8: sigConfigServer

        public sigConfigServer(String[] args)
        {
            // Initialise variables and check commandline arguments for values (for manual specific logging)
            InitializeComponent();
            this.AutoLog = false;
            sigConfigServerServiceLog = new System.Diagnostics.EventLog();
            string logSource = "sigConfigServerSource";
            string logName = "sigConfigServerLog";

            if (args.Count() > 0)
            {
                logSource = args[0];
            }
            if (args.Count() > 1)
            {
                logSource = args[1];
            }

            if (!System.Diagnostics.EventLog.SourceExists(logSource))
            {
                System.Diagnostics.EventLog.CreateEventSource(logSource, logName);
            }

            sigConfigServerServiceLog.Source = logSource;
            sigConfigServerServiceLog.Log = logName;

            // Logging
            sigConfigServerServiceLog.WriteEntry("Roswell Email Signature Sync service (server mode) created.");

            this.OnStart();
        }
开发者ID:probablytom,项目名称:sigConfig,代码行数:31,代码来源:SigConfigServer.cs


示例9: OnStart

        protected override void OnStart(string[] args)
        {
            ConfigurationManager.RefreshSection("AppSetings");

            string logSource = ConfigurationManager.AppSettings["LogSource"];
            string logName = ConfigurationManager.AppSettings["LogName"];

            if (!EventLog.SourceExists(logSource))
            {
                EventLog.CreateEventSource(logSource, logName);
            }

            log = new EventLog { Source = logSource };

            int port;
            if (!int.TryParse(ConfigurationManager.AppSettings["ListenPort"], out port))
            {
                port = 9999;
            }

            server = new DashboardServer(port, new PrivateDataSource());
            server.Log = new EventLogger { EventLog = log };

            server.Start();
        }
开发者ID:nerduino,项目名称:Dashboard,代码行数:25,代码来源:DashboardService.cs


示例10: OnUnhandledException

        void OnUnhandledException(object o, UnhandledExceptionEventArgs e) {
            // Let this occur one time for each AppDomain.
            if (Interlocked.Exchange(ref _unhandledExceptionCount, 1) != 0)
                return;

            StringBuilder message = new StringBuilder("\r\n\r\nUnhandledException logged by UnhandledExceptionModule.dll:\r\n\r\nappId=");

            string appId = (string) AppDomain.CurrentDomain.GetData(".appId");
            if (appId != null) {
                message.Append(appId);
            }
            

            Exception currentException = null;
            for (currentException = (Exception)e.ExceptionObject; currentException != null; currentException = currentException.InnerException) {
                message.AppendFormat("\r\n\r\ntype={0}\r\n\r\nmessage={1}\r\n\r\nstack=\r\n{2}\r\n\r\n",
                                     currentException.GetType().FullName, 
                                     currentException.Message,
                                     currentException.StackTrace);
            }           

            EventLog Log = new EventLog();
            Log.Source = _sourceName;
            Log.WriteEntry(message.ToString(), EventLogEntryType.Error);
        }
开发者ID:dblock,项目名称:sncore,代码行数:25,代码来源:UnhandledExceptionModule.cs


示例11: Main

        static void Main()
        {
            if (!EventLog.SourceExists("SelfMailer"))
            {
                EventLog.CreateEventSource("SelfMailer", "Mes applications");
            }
            EventLog eventLog = new EventLog("Mes applications", ".", "SelfMailer");
            eventLog.WriteEntry("Mon message", EventLogEntryType.Warning);

            BooleanSwitch booleanSwitch = new BooleanSwitch("BooleanSwitch", "Commutateur booléen.");
            TraceSwitch traceSwitch = new TraceSwitch("TraceSwitch", "Commutateur complexe.");

            TextWriterTraceListener textListener = new TextWriterTraceListener(@".\Trace.txt");
            Trace.Listeners.Add(textListener);

            Trace.AutoFlush = true;
            Trace.WriteLineIf(booleanSwitch.Enabled, "Démarrage de l'application SelfMailer");

            Project = new Library.Project();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Forms.Main());

            Trace.WriteLineIf(traceSwitch.TraceInfo, "Arrêt de l'application SelfMailer");
        }
开发者ID:hugonjerome,项目名称:CSharp-5-Developpez-des-applications-Windows-avec-Visual-Studio-2012,代码行数:25,代码来源:Program.cs


示例12: Logger

 /// <summary>
 /// Creating an EventSource requires certain permissions, which by default a IIS AppPool user does not have.
 /// In this case just ignore security exceptions.
 /// In order to make this work, the eventsource needs to be created manually
 /// </summary>
 public Logger(string name, string source) {
   try {
     log = new EventLog();
     log.Source = source;
   }
   catch (Exception) { }
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:12,代码来源:Logger.cs


示例13: ReportProcess

 /// <summary>
 /// 建構子
 /// </summary>
 /// <param name="SetProcessFile">處理的檔案</param>
 /// <param name="SeteventLog1">事件檢示器物件</param>
 public ReportProcess(string SetProcessFile,
                      EventLog SeteventLog1
                      )
 {
     ProcessFile = SetProcessFile;
     eventLog1 = SeteventLog1;
 }
开发者ID:ChiangHanLung,项目名称:PIC_VDS,代码行数:12,代码来源:ReportProcess.cs


示例14: TaskSchedulerManager

 public TaskSchedulerManager(EventLog el)
 {
     scheduler = new TaskScheduler.TaskScheduler();
     scheduler.Connect(null, null, null, null);
     rootFolder = scheduler.GetFolder("\\");
     eventLog = el;
 }
开发者ID:shintaro,项目名称:Fake_iSCT_Service,代码行数:7,代码来源:TaskSchedulerManager.cs


示例15: SendersManager

 public SendersManager()
 {
     new EventLogPermission(EventLogPermissionAccess.Administer, ".").Demand();
     _localLog = new EventLog("Application", ".", "el2slservice");
     _senders = new List<SyslogSender>();
     _config = new El2SlConfig();
 }
开发者ID:Cogitarian,项目名称:el2sl,代码行数:7,代码来源:SendersManager.cs


示例16: Write

        /// <summary>
        /// Writes the specified message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="execption">The execption.</param>
        /// <param name="eventLogType">Type of the event log.</param>
        private void Write(object message, Exception execption, EventLogEntryType eventLogType)
        {
            StringBuilder sb = new StringBuilder();

            System.Diagnostics.EventLog eventLogger = new System.Diagnostics.EventLog();
            if (!System.Diagnostics.EventLog.SourceExists(eventLogSource))
            {
                System.Diagnostics.EventLog.CreateEventSource(eventLogSource, eventLogName);
            }

            sb.Append(message).Append(NEW_LINE);
            while (execption != null)
            {
                sb.Append("Message: ").Append(execption.Message).Append(NEW_LINE)
                .Append("Source: ").Append(execption.Source).Append(NEW_LINE)
                .Append("Target site: ").Append(execption.TargetSite).Append(NEW_LINE)
                .Append("Stack trace: ").Append(execption.StackTrace).Append(NEW_LINE);

                // Walk the InnerException tree
                execption = execption.InnerException;
            }

            eventLogger.Source = eventLogSource;
            eventLogger.WriteEntry(String.Format(ERROR_MSG, eventLogName, sb), eventLogType);
        }
开发者ID:JackFong,项目名称:ServiceStack.Logging,代码行数:31,代码来源:EventLogger.cs


示例17: WebQ

        public WebQ(EventLog eventLog)
        {
            _eventLog = eventLog;

            Directory.CreateDirectory(DATA_FOLDER);
            Load();
        }
开发者ID:brigs,项目名称:ConDep,代码行数:7,代码来源:WebQ.cs


示例18: Init

        public void Init(HttpApplication context)
        {
            //注册对于全局错误的记录
            context.Error += OnError;

            #region 记录UnhandledException

            //使用Double-Check机制保证在多线程并发下只注册一次UnhandledException处理事件
            if (!hasInitilized)
            {
                lock (syncRoot)
                {
                    if (!hasInitilized)
                    {
                        //1. 按照.net的习惯,依然首先将该内容写入到系统的EventLog中
                        string webenginePath = Path.Combine(RuntimeEnvironment.GetRuntimeDirectory(), "webengine.dll");
                        //通过webengine.dll来查找asp.net的版本,eventlog的名称由asp.net+版本构成
                        if (!File.Exists(webenginePath))
                        {
                            throw new Exception(String.Format(CultureInfo.InvariantCulture, "Failed to locate webengine.dll at '{0}'.  This module requires .NET Framework 2.0.", webenginePath));
                        }

                        FileVersionInfo ver = FileVersionInfo.GetVersionInfo(webenginePath);
                        eventSourceName = string.Format(CultureInfo.InvariantCulture, "ASP.NET {0}.{1}.{2}.0", ver.FileMajorPart, ver.FileMinorPart, ver.FileBuildPart);

                        if (!EventLog.SourceExists(eventSourceName))
                        {
                            throw new Exception(String.Format(CultureInfo.InvariantCulture, "There is no EventLog source named '{0}'. This module requires .NET Framework 2.0.", eventSourceName));
                        }

                        //在出现问题后将内容记录下来
                        AppDomain.CurrentDomain.UnhandledException += (o, e) =>
                                                                          {
                                                                              if (Interlocked.Exchange(ref unhandledExceptionCount, 1) != 0)
                                                                                  return;

                                                                              string appId = (string)AppDomain.CurrentDomain.GetData(".appId");
                                                                              appId = appId ?? "No-appId";

                                                                              Exception currException;
                                                                              StringBuilder sb = new StringBuilder();
                                                                              sb.AppendLine(appId);
                                                                              for (currException = (Exception)e.ExceptionObject; currException != null; currException = currException.InnerException)
                                                                              {
                                                                                  sb.AppendFormat("{0}\n\r", currException.ToString());
                                                                                  _log.Error(currException);
                                                                              }

                                                                              EventLog eventLog = new EventLog { Source = eventSourceName };
                                                                              eventLog.WriteEntry(sb.ToString(), EventLogEntryType.Error);
                                                                          };

                        //初始化后设置该值为true保证不再继续注册事件
                        hasInitilized = true;
                    }
                }
            }

            #endregion
        }
开发者ID:huayumeng,项目名称:ytoo.service,代码行数:60,代码来源:GlobalErrorHandlerModule.cs


示例19: LogEventInfo

        public static void LogEventInfo(string info)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                string sourceName = @"Medalsoft";
                string logName = @"WF";

                if (EventLog.SourceExists(sourceName))
                {

                    string oldLogName = EventLog.LogNameFromSourceName(sourceName, System.Environment.MachineName);
                    if (!oldLogName.Equals(logName))
                    {
                        EventLog.Delete(oldLogName);
                    }
                }

                if (!EventLog.Exists(logName))
                {
                    EventLog.CreateEventSource(sourceName, logName);
                }

                EventLog myLog = new EventLog();
                myLog.Source = sourceName;
                myLog.Log = logName;

                myLog.WriteEntry(info, EventLogEntryType.Information);

            });
        }
开发者ID:porter1130,项目名称:MOSSArt,代码行数:30,代码来源:CommonUtil.cs


示例20: Button_Click

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string svcPath = Path.Combine(Environment.CurrentDirectory, "DS4ToolService.exe");

            ServiceController sc = new ServiceController(Constants.SERVICE_NAME, Environment.MachineName);
            ServiceControllerPermission scp = new ServiceControllerPermission(ServiceControllerPermissionAccess.Control, Environment.MachineName, Constants.SERVICE_NAME);
            scp.Assert();
            sc.Refresh();
            ServiceInstaller si = new ServiceInstaller();

            if (si.DoesServiceExist(Constants.SERVICE_NAME))
            {
                if (sc.Status == ServiceControllerStatus.Running)
                    sc.Stop();

                sc.WaitForStatus(ServiceControllerStatus.Stopped);
                si.UnInstallService(Constants.SERVICE_NAME);
                MessageBox.Show("Service removed");
            }

            EventLog eventLog = new EventLog();
            eventLog.Source = Constants.SERVICE_NAME;
            eventLog.Log = "Application";
            if (!EventLog.SourceExists(eventLog.Source))
            {
                EventLog.DeleteEventSource(eventLog.Source, Environment.MachineName);
                MessageBox.Show("EventLog removed");
            }
        }
开发者ID:kenzya,项目名称:ds4ui,代码行数:29,代码来源:MainWindow.xaml.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Diagnostics.EventLogPermission类代码示例发布时间:2022-05-26
下一篇:
C# Diagnostics.EventInstance类代码示例发布时间: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