Windows 로그 관리자에 시스템 프로그램 로그 정보 쓰기

1245 단어 windows
표준 샘플 코드:
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);

            }

        }

    }

}


좋은 웹페이지 즐겨찾기