码迷,mamicode.com
首页 > Windows程序 > 详细

向Windows 日志管理器写入系统程序日志信息

时间:2015-07-15 13:01:53      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:

标准样例代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Diagnostics.Eventing;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string LogName = "Nieweiking_Log";
            string SourceName = "Nieweiking的程序";
            if (!EventLog.SourceExists(SourceName))
            {
                var EventSourceData = new EventSourceCreationData(SourceName, LogName);
                EventLog.CreateEventSource(EventSourceData);
            }

            using (var log = new EventLog(LogName, ".", SourceName))
            {
                log.WriteEntry("Message 1");
                log.WriteEntry("Message 2", EventLogEntryType.Warning);;
                log.WriteEntry("Message 2", EventLogEntryType.Information, 33);
            }
        }
    }
}

  

向Windows 日志管理器写入系统程序日志信息

标签:

原文地址:http://www.cnblogs.com/qq458978/p/4647904.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!