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


C# EventLog.WriteEntry方法代码示例

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


在下文中一共展示了EventLog.WriteEntry方法的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: Write

 public override void Write(object TraceInfo)
 {
     try
       {
     if (!(TraceInfo is LogInfo))
       throw new TraceListenerException(TraceInfo, "Use 'Write(object)' override and pass 'TraceInfo' instance");
     LogInfo info = TraceInfo as LogInfo;
     this.Output(info);
     if (info.Type != LogType.Execption && info.Type != LogType.HandlerExecutionError)
       return;
     if (!EventLog.SourceExists(((object) info.Type).ToString()))
       EventLog.CreateEventSource(((object) info.Type).ToString(), "TradePlatform.MT4");
     EventLog eventLog = new EventLog();
     eventLog.Source = ((object) info.Type).ToString();
     if (info.Exception != null)
     {
       string message = string.Empty;
       for (; info.Exception != null; info.Exception = info.Exception.InnerException)
     message = message + (object) info.Exception + "\n\n";
       eventLog.WriteEntry(message, EventLogEntryType.Error);
     }
     else
       eventLog.WriteEntry(info.Message, EventLogEntryType.Error);
       }
       catch
       {
       }
 }
开发者ID:prog76,项目名称:tradeplatform,代码行数:28,代码来源:EventLogger.cs

示例3: 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

示例4: WriteToEventLog

        public void WriteToEventLog(string strLogName, string strSource, string strErrDetail, int level)
        {
            try
            {
                if (!EventLog.SourceExists(strSource))
                    this.CreateLog(strSource, strLogName);

                using (EventLog SQLEventLog = new EventLog())
                {
                    SQLEventLog.Source = strSource;

                    if (level == 1)
                        SQLEventLog.WriteEntry(String.Format("[{0}] \t {1} ", DateTime.Now.ToString(), Convert.ToString(strErrDetail)), EventLogEntryType.Error);
                    else if (level == 2)
                        SQLEventLog.WriteEntry(String.Format("[{0}] \t {1} ", DateTime.Now.ToString(), Convert.ToString(strErrDetail)), EventLogEntryType.Information);

                }
            }
            catch (Exception ex)
            {
                using (EventLog SQLEventLog = new EventLog())
                {
                    SQLEventLog.Source = strSource;
                    SQLEventLog.WriteEntry(String.Format("[{0}] \t {1} ", DateTime.Now.ToString(), Convert.ToString(ex.Message)),
                    EventLogEntryType.Information);
                }
            }
        }
开发者ID:m2ag,项目名称:Notificador,代码行数:28,代码来源:LoggerRepository.cs

示例5: OnStart

        protected override void OnStart(string[] args)
        {
            var eventLog = new EventLog {Source = "Application"};
            eventLog.WriteEntry(_environment.ApplicationName + "- Application Base Path: " + _environment.ApplicationBasePath, EventLogEntryType.Information);

            try
            {
                InitializeConfiguration();
                Debug.WriteLine("Initializing Service: {ServiceName}", _serviceSettings.ServiceName);
                InitializeContainer();
                InitializeLogging();

                Log.Information("Starting Service: {ServiceName}", _serviceSettings.ServiceName);

                if (StartAction == null)
                {
                    throw new NotImplementedException("A StartAction must be defined in your 'Program' static constructor.");
                }
                StartAction(args);
                Log.Information("Service: {ServiceName} was started.", _serviceSettings.ServiceName);
            }
            catch (Exception ex)
            {
                if (!Environment.UserInteractive)
                {
                    //In case logging is hosed, make sure this goes to the event log
                    eventLog.WriteEntry("An error occurred starting the service. " + ex, EventLogEntryType.Error);
                }

                Log.Error(ex, "Service failed to start {ServiceName}", _serviceSettings.ServiceName);
                throw;
            }
        }
开发者ID:eswann,项目名称:NSB_Perf,代码行数:33,代码来源:ProgramBase.cs

示例6: SyslogSender

 public SyslogSender(El2SlConfig config, EventLog eventLog, EventLog localLog)
 {
     _enUS = new CultureInfo("en-US");
     _localLog = localLog;
     _config   = config;
     _eventLog = eventLog;
     _encoding = new UTF8Encoding();
     _eventLog.EnableRaisingEvents = true;
     _eventLog.EntryWritten += eventLog_EntryWritten;
     _udpClient = new UdpClient();
     _udpClient.DontFragment = false;
     _udpClient.Connect(_config.Host, _config.Port);
     try
     {
         if (_udpClient.Client.Connected)
         {
             _localLog.WriteEntry(
                 string.Format("el2slservice connected to syslog for send events of {0}",_eventLog.LogDisplayName),
                 EventLogEntryType.Information);
         }
     }
     catch (SocketException se)
     {
         _localLog.WriteEntry("el2slservice can not connect to syslog. Reason: " + se.Message, EventLogEntryType.Error);
     }
 }
开发者ID:Cogitarian,项目名称:el2sl,代码行数:26,代码来源:SyslogSender.cs

示例7: OnStart

        //private void InitializeComponent()
        //{
        //    this.ServiceName = "LogChipper"; 
        //    this.CanHandleSessionChangeEvent = false;
        //    this.CanPauseAndContinue = false;
        //    this.CanShutdown = true;
        //    this.CanStop = Properties.Settings.Default.svcCanStop;
        //}

        protected override void OnStart(string[] args)
        {
            // prep for writing to local event log
            string eventLogName = Properties.Settings.Default.eventLogName;
            string eventLogSource = Properties.Settings.Default.eventLogSource;
            string machineName = ".";
            // warning: Event Log Source must have already been created during the installation
            eventLogger = new EventLog(eventLogName, machineName, eventLogSource);
            eventLogger.WriteEntry("LogChipper syslog forwarding service has started.", EventLogEntryType.Information, 0);

            // prep for posting to remote syslog
            bool useTCP = Properties.Settings.Default.syslogProtocol.ToUpper().Contains("TCP");
            syslogForwarder = new Syslog.Client(
                (string)Properties.Settings.Default.syslogServer,
                (int)Properties.Settings.Default.syslogPort,
                useTCP,
                (int)Syslog.Facility.Syslog,
                (int)Syslog.Level.Information);
            syslogForwarder.Send("[LogChipper syslog forwarding service has started.]");

            // prep to tail the local log file
            //fileName = Properties.Settings.Default.logFilePath;
            if (!File.Exists(fileName))
            {
                eventLogger.WriteEntry("Cannot locate target log file; exiting service.", EventLogEntryType.Error, 404);
                this.Stop();
                Environment.Exit(404); // not very graceful, but prevents more error messages from continuing OnStart after OnStop

                // TODO: handle missing target file more gracefully
                //    bool found = false;
                //
                //    // re-test every minute for 15 minutes
                //    for (int i = 0; i < 15; i++)
                //    {
                //        eventLogger.WriteEntry("Target log file not found; please check the configuration.", EventLogEntryType.Warning, 2);
                //        System.Threading.Thread.Sleep(60 * 1000);
                //        if (File.Exists(fileName))
                //        {
                //            found = true;
                //            break;
                //        }
                //    }
                //    if (!found)
                //    {
                //        eventLogger.WriteEntry("Target log file still doesn't exist; exiting service.", EventLogEntryType.Error, 404);
                //        Environment.Exit(1); // TODO: correct way to exit?
                //    }
            }

            // spin your thread
            if ((workerThread == null) || ((workerThread.ThreadState & 
                (System.Threading.ThreadState.Unstarted | System.Threading.ThreadState.Stopped)) != 0))
            {
                workerThread = new Thread(new ThreadStart(ServiceWorkerMethod));
                workerThread.Start();
            }
        }
开发者ID:ewall,项目名称:LogChipper.NET,代码行数:66,代码来源:LogChipperService.cs

示例8: TraspasaDocumentos

        public void TraspasaDocumentos()
        {
            List<IOperacion> lstsrvmiddle = null;
            int nRt = 0;
            ILog oLog = null;
            string sAux = string.Empty;

            EventLog ELog = new EventLog("Application", ".", _sSourceEvLog);
            String sBasePath = System.AppDomain.CurrentDomain.BaseDirectory;
            try
            {
                oLog = new ooLogSrv();
                ELog.WriteEntry(string.Format("Antes de config spring, base path: {0}", sBasePath));

                    try
                    {
                        _appContext = new XmlApplicationContext(Path.Combine(sBasePath, "di.config.xml"));
                    }
                    catch (Exception ex)
                    {
                        oLog.LogException(ex);
                    }
                    ELog.WriteEntry(string.Format("Despues de config spring"));
                    lstsrvmiddle = (List<IOperacion>)_appContext.GetObject("pluginComponentesTraspasoDoc");
                    oLog.LogInfo(string.Format("Application started at  {0}", DateTime.Now));
                    nRt = 0;

                    ELog.WriteEntry(string.Format("Application started at '{0}'", DateTime.Now));

                    try
                    {
                        foreach (IOperacion srvOp in lstsrvmiddle)
                        {
                            srvOp.oLog = oLog;
                            nRt = srvOp.lTraspasar();
                            oLog.LogInfo(string.Format("Application finish procesing of '{0}' registers of  type {1} at '{2}'", nRt, srvOp.GetType().Name, DateTime.Now));
                        }
                    }
                    catch (Exception ex)
                    {
                        oLog.LogException(ex);
                    }

            }
            catch (Exception ex)
            {
                ELog.WriteEntry(string.Format("Excepcion: {0}", ex));
                oLog.LogException(ex);
            }
            finally
            {
                oLog.LogInfo(string.Format("Servicio finaliza ejecucion a las '{0}'", DateTime.Now));
                Thread.CurrentThread.Abort(); //se finaliza el thread
            }
        }
开发者ID:aleloyola,项目名称:srvFEmiddle,代码行数:55,代码来源:srvFEmiddle.cs

示例9: timer1_Elapsed

        void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            #region 事件日志操作
            //不允许向Security里写数据

            #region 写到Application里
            {
                if (!EventLog.SourceExists("CrazyIIS_Application"))
                {
                    EventLog.CreateEventSource("CrazyIIS_Application", "Application");
                }

                EventLog log = new EventLog();
                log.Source = "CrazyIIS_Application";
                log.WriteEntry("柳永法提醒您,这是:CrazyIIS_Application", EventLogEntryType.FailureAudit);
                log.WriteEntry("柳永法提醒您,这是:CrazyIIS_Application", EventLogEntryType.Information);
                log.WriteEntry("柳永法提醒您,这是:CrazyIIS_Application", EventLogEntryType.Warning);
            }
            #endregion

            #region 写到System里
            {
                if (!EventLog.SourceExists("CrazyIIS_System"))
                {
                    EventLog.CreateEventSource("CrazyIIS_System", "System");
                }

                EventLog log = new EventLog();
                log.Source = "CrazyIIS_System";
                log.WriteEntry("柳永法提醒您,这是:CrazyIIS_System", EventLogEntryType.FailureAudit);
                log.WriteEntry("柳永法提醒您,这是:CrazyIIS_System", EventLogEntryType.Information);
                log.WriteEntry("柳永法提醒您,这是:CrazyIIS_System", EventLogEntryType.Warning);
            }
            #endregion

            // EventLog.Delete("我的软件");
            // EventLog.DeleteEventSource("CrazyIIS");

            if (!EventLog.SourceExists("CrazyIIS"))
            {
                EventLog.CreateEventSource("CrazyIIS", "我的软件");
            }

            EventLog myLog = new EventLog();
            myLog.Source = "CrazyIIS";
            myLog.WriteEntry("CrazyIIS", EventLogEntryType.Error, 12345, 22222);
            myLog.WriteEntry("CrazyIIS", EventLogEntryType.FailureAudit, 12345, 22222);
            #endregion
        }
开发者ID:henrydem,项目名称:yongfa365doc,代码行数:49,代码来源:Service1.cs

示例10: 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

示例11: 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

示例12: 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

示例13: Write

        public override void Write(LogEntry entry)
        {
            EventLogEntryType type;

            switch (entry.Level)
            {
                case Level.Debug:
                case Level.Trace:
                case Level.Info:
                    type = EventLogEntryType.Information;
                    break;
                case Level.Warn:
                    type = EventLogEntryType.Warning;
                    break;
                case Level.Error:
                case Level.Fatal:
                    type = EventLogEntryType.Error;
                    break;
                default:
                    type = EventLogEntryType.Information;
                    break;
            }

            using (var eventLog = new EventLog { Source = EventLogSource ?? entry.Source })
            {
                var fmt = EntryFormatter ?? entry.Logger.LogManager.GetFormatter<string>();
                var msg = fmt.Convert(entry);
                eventLog.WriteEntry(msg, type);
            }
        }
开发者ID:ajayanandgit,项目名称:Logging-1,代码行数:30,代码来源:EventLogLogger.cs

示例14: 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

示例15: 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


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