zoukankan      html  css  js  c++  java
  • C#写入系统日志(日志位置)

    程序其实很简单直接贴代码了

     

     eventLog1是一个控件

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    
    namespace SetEventLog
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                if (System.Diagnostics.EventLog.SourceExists("ZhyScoure"))      //判断是否存在事件源
                {
                    System.Diagnostics.EventLog.SourceExists("ZhyScoure");      //删除事件源注册
                }
                System.Diagnostics.EventLog.CreateEventSource("ZhyScoure", "NewLog1");   //创建日志信息
                eventLog1.Log = "NewLog1";      //设置日志名称
                eventLog1.Source = "ZhyScoure";     //事件源名称
                eventLog1.MachineName = ".";
            }
    
            private void btnWriteLog_Click(object sender, EventArgs e)
            {
                if (System.Diagnostics.EventLog.Exists("NewLog1"))
                {
                    if (textBox1.Text != "")
                    {
                        eventLog1.WriteEntry(textBox1.Text.ToString());
                        MessageBox.Show("日志写入成功");
                        textBox1.Text = "";
                    }
                    else
                    {
                        MessageBox.Show("日志内容不能为空");
                    }
                }
                else
                {
                    MessageBox.Show("日志不存在");
                }
            }
        }
    }
    

      

    日志写入了那到哪儿去了呢?

    键盘:WIn+R 

    ok了

    see you again
  • 相关阅读:
    ubuntu下安装maven
    159.Longest Substring with At Most Two Distinct Characters
    156.Binary Tree Upside Down
    155.Min Stack
    154.Find Minimum in Rotated Sorted Array II
    153.Find Minimum in Rotated Sorted Array
    152.Maximum Product Subarray
    151.Reverse Words in a String
    150.Evaluate Reverse Polish Notation
    149.Max Points on a Line
  • 原文地址:https://www.cnblogs.com/zfdzzz/p/11821893.html
Copyright © 2011-2022 走看看