Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >C# 生成事件log

C# 生成事件log

作者头像
zls365
发布于 2020-08-19 03:04:13
发布于 2020-08-19 03:04:13
53500
代码可运行
举报
文章被收录于专栏:CSharp编程大全CSharp编程大全
运行总次数:0
代码可运行
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
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;
using System.Threading;
using System.IO;
namespace WindowsFormsApp31
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
        }
        private string str = "";
        private void Form1_Load(object sender, EventArgs e)
        {
            Thread th1 = new Thread(test1);
            th1.Start();
            Thread th2 = new Thread(test2);
            th2.Start();
            timer1.Enabled = true;
        }
        public void test1()
        {
            try
            {
                if (!Directory.Exists(@"d:\test"))
                    Directory.CreateDirectory(@"d:\test");
                if (!File.Exists(@"d:\test\1.txt"))
                    File.Create(@"d:\test\1.txt").Close();
                StreamWriter sw = new StreamWriter(@"d:\test\1.txt", true);
                for (int i = 0; i < 100; i++)
                {
                    sw.WriteLine(i.ToString());
                }
                sw.Close();
                int k = 0;
                k = k / 0;//引发异常,写入事件log
            }
            catch(Exception ex)
            {
                StreamWriter sw = new StreamWriter(@"d:\test\1.txt", true);
                sw.WriteLine(ex.ToString());
                sw.Close();
            }
        }
        public void test2()
        {
            try
            {
                if (!Directory.Exists(@"d:\test"))
                    Directory.CreateDirectory(@"d:\test");
                if (!File.Exists(@"d:\test\2.txt"))
                    File.Create(@"d:\test\2.txt").Close();
                StreamWriter sw = new StreamWriter(@"d:\test\2.txt", true);
                for (int i = 0; i < 100; i++)
                {
                    sw.WriteLine(i.ToString());
                }
                sw.Close();
            }
            catch(Exception ex)
            {
                StreamWriter sw = new StreamWriter(@"d:\test\2.txt", true);
                sw.WriteLine(ex.ToString());
                sw.Close();
            }
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            str += "1";
            richTextBox1.Text = str;
        }
    }
}

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

System.DivideByZeroException: 尝试除以零。

在 WindowsFormsApp31.Form1.test1() 位置 C:\Users\lin\source\repos\WindowsFormsApp31\WindowsFormsApp31\Form1.cs:行号 58

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2019-10-29,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 CSharp编程大全 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
C# 求方差和平均值并保存
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace ConsoleApplication7 { class Program { static void Main(string[] args) { List
zls365
2020/08/19
9950
C# 软件开机启动
方法2:添加环境变量 , 计算行--属性--高级系统设置--环境变量--系统变量里面设置.
zls365
2020/08/19
6900
C# 软件开机启动
c#文件流操作
MaybeHC
2024/04/23
1370
c#文件流操作
C# 获取txt文件邮箱号码并去重复
这是咱们C# 开发交流群里好友昨天提的问题: 主要是从txt文件中删除重复的邮箱号 以下是实现的代码: 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.Windo
zls365
2020/08/19
1.1K0
C# 获取txt文件邮箱号码并去重复
C# 软件版本号
//build 等于自当地时间 2000 年 1 月 1 日以来的天数 //revision等于自当地时间午夜以来的秒数/2 // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, // 方法是按如下所示使用“*”:
zls365
2020/08/19
6990
C# 软件版本号
Unity Editor 基础篇(三):自定义窗口
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
bering
2019/12/03
2K0
C#实例(经典):四路光电开关&激光雷达数据采集和波形图绘制
这篇文章涉及较多C#重要知识点,如果都能看懂,你至少可以算得上入门了!有兴趣的同志可以下载源码调试.
zls365
2020/10/30
1.8K0
C#实例(经典):四路光电开关&激光雷达数据采集和波形图绘制
C#封装的常用文件操作代码类
这个C#类封装了我们经常能用到的文件操作方法,包括读写文件、获取文件扩展名、复制文件、追加内容到文件、删除文件、移动文件、创建目录、递归删除文件及目录、列目录、列文件等,不可多得。
用户7108768
2021/11/02
9500
c# UDP/TCP协议简单实现(简单聊天工具)
1、用户登陆于服务器通信用到的tcp协议,服务器接收到用户登陆信息(包括ip,端口,用户名等)后,返回已经登陆的用户列表信息(包括ip,端口,用户名等)给这个用户,同时服务器使用Udp协议向已经登陆的用户发送最新用户列表(包括ip,端口,用户名等)用于更新用户列表
冰封一夏
2019/09/11
1.4K0
C#常用操作类库四(File操作类)
View Code    public class FileHelper : IDisposable     {         private bool _alreadyDispose = false;         #region 构造函数         public FileHelper()         {             //             // TODO: 在此处添加构造函数逻辑             //         }         ~FileHelpe
跟着阿笨一起玩NET
2018/09/18
1K0
VS 2010一步步开发windows服务(windows service)
 基于0起步来创建一个服务,做到简单的记录时间日志功能,其具体招行方法可自行添加。 1.创建服务 2.删除默认服务文件 3.添加自己的服务文件 4.更改启动项目 5. 引用 using System.
欢醉
2018/01/22
8370
VS 2010一步步开发windows服务(windows service)
日志帮助类
 1.代码 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Configuration; using System.Reflection; namespace LogHelper.Common { public class LogHelper { private string logFile
用户1055830
2018/01/18
7210
日志帮助类
C# excel文件导入导出
在C#交流群里,看到很多小伙伴在excel数据导入导出到C#界面上存在疑惑,所以今天专门做了这个主题,希望大家有所收获!
zls365
2020/08/19
4.1K0
C# excel文件导入导出
C#文件和文件夹输入输出流代码
C#删除文件 string delFile = Server.MapPath(“.”)+”\\myTextCopy.txt”; File.Delete(delFile);
全栈程序员站长
2022/07/15
8180
C# 学习笔记(19)—— 文件操作
无论要开发什么样的应用程序,我们都不可避免地要对文件进行操作,所以掌握相关知识就显得格外重要了。.Net Framework 对文件操作提供了很好的支持,它让我们的编程工作变得简单
Karl Du
2023/10/20
3060
C# 文件流操作
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; using System.IO; namespace WindowsFormsA
zls365
2020/08/19
9780
C# 文件流操作
C#常用目录文件操作封装类代码
这个c#类封装了常用的目录操作,包括列出目录下的文件、检测目录是否存在、得到目录下的文件列表、检测目录是否为空、查找目录下的文件等等功能
用户7108768
2021/11/03
1.1K0
操作文件系统
创建和写文本文件 新建.aspx(主要是StreamWriter 和StreamReader ) using System.IO ;//不可以少了
Java架构师必看
2021/03/22
3910
C# 探测器测试系统
运行效果: 重要知识点: 控件循环遍历操控; 队列数组的应用: private Queue<double>[] dataQueue = new Queue<double>[8]; //把
zls365
2020/08/19
1.5K0
C# 探测器测试系统
C# 简单日志文本输出
第一种  直接文件IO流写日志文件 using System.IO; public static void WriteLog(string strLog) { string sFilePath="d:\\"+DateTime.Now.ToString("yyyyMM"); string sFileName = "rizhi" + DateTime.Now.ToString("dd") + ".log"; sFileName = sFilePath+ "\\"+sFileName; //文件的绝对
庞小明
2018/04/16
3.2K0
相关推荐
C# 求方差和平均值并保存
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验