}
///
/// 操作文件实现日志
///
///
日志内容
///
存放日志的目录,如果想默认存在项目的 Debag 下,请
public Form1()
{
InitializeComponent();
public partial class Form1 : Form
{
using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Text;
7 using System.Windows.Forms;
8 using System.IO;
9
10 namespace LogDemo
11 {
12
13
14
15
16
17
18
19
20
21
22
输入 Null
23
24
25
26
27
28
29
30
31
32
33
34
年" + DateTime.Now.Month.ToString()+"月";
35
36
37
38
39
40
41
FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
private void logger(String msg,string lonPath)
{
string LogPath = null;
if (lonPath != null)
{
LogPath = lonPath;
LogPath =Application.StartupPath;
}
else
{
}
}
string filePath = LogPath + "\\" + DateTime.Now.Year.ToString()+"
string fileName = DateTime.Now.Day.ToString() + "日" + ".Log";
string filePathAll = filePath + "\\" + fileName;
if (!System.IO.Directory.Exists(filePath))
{
System.IO.Directory.CreateDirectory(filePath);
FileStream filestream = new FileStream(filePathAll,
StreamWriter writer = new StreamWriter(filestream,
writer.BaseStream.Seek(0, SeekOrigin.End);
writer.WriteLine("{0} {1}", DateTime.Now.TimeOfDay , msg);
writer.Flush();
writer.Close();
filestream.Close();
//测试方法
private void button1_Click(object sender, EventArgs e)
{
}
try
{
byte str=0 ;
42
System.Text.Encoding.Default);
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 }
if (true)
{
}
else
{
}
}
}
str = (byte)Convert.ToSByte(600);
str = (byte)Convert.ToSByte(500);
}
}
catch(Exception ex)
{
logger(ex.Message,null);