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


C# Diagnostics.EventLog类代码示例

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


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


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