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
  • 相关阅读:
    awk 入门教程【转】
    xargs 命令教程【转】
    redis 执行lua脚本
    SpringMVC 执行过程分析
    EurekaClient 服务注册、发现、续约
    Springboot 自动配置 & 自定义Starter
    Netty 实现HttpServer
    Spring中@Import 用法
    Netty自定义任务&Future-Listener机制
    Springboot + Netty + WebSocket 实现简单的聊天
  • 原文地址:https://www.cnblogs.com/zfdzzz/p/11821893.html
Copyright © 2011-2022 走看看