在c#中写入具有自动标识no的日志(txt)文件 [英] To Write Log (txt) file with auto identity no in c#

查看:208
本文介绍了在c#中写入具有自动标识no的日志(txt)文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有这样的txt文件



样本O / p:



30/12/2014 11:59:53

条形码 - >'4987168011306'包装 - >'单位'在积极促销中用于分店'DMCurepipe,ESPACE'



30/12/2014 11:59:53

条形码 - >'6091230334014'包裹 - >'单位'在积极促销中为分店' DMCurepipe,ESPACE'



我需要自动身份不喜欢1,2,3等



预计O / p:



30/12/2014 11:59:53

1)条形码 - >'4987168011306'带包装 - > ;'Unit'正在积极推广分行'DMCurepipe,ESPACE'



30/12/2014 11:59:53

2 )条形码 - >'6091230334014'与包 - >'单位'在积极促销分支'DMCurepipe,ESPACE'



i已经创建了一个新的txt文件来写日志和下一行我需要编写错误日志与唯一不仅像1,2,3等...我没有使用任何循环写自动没有如何完成这个? ??

I have a txt file like this in my project

Sample O/p :

30/12/2014 11:59:53
Barcode->'4987168011306' with package ->'Unit' is in Active Promotion for Branch 'DMCurepipe,ESPACE'

30/12/2014 11:59:53
Barcode->'6091230334014' with package ->'Unit' is in Active Promotion for Branch 'DMCurepipe,ESPACE'

I need auto identity no like 1,2,3 etc

Expected O/p :

30/12/2014 11:59:53
1)Barcode->'4987168011306' with package ->'Unit' is in Active Promotion for Branch 'DMCurepipe,ESPACE'

30/12/2014 11:59:53
2)Barcode->'6091230334014' with package ->'Unit' is in Active Promotion for Branch 'DMCurepipe,ESPACE'

i have created a new txt file to write a log and very next line i need to write error log with unique no just like 1,2,3 etc...i didn't use any loop to write auto no how to accomplish this???

推荐答案

你不喜欢

int i = 1;

每次你写的你将它传递给写字线,然后递增。



类似

//在某些方法中有这个

streamwriter sw;

sw.WriteLine(String.Format({0} \r\ n {1} {2} \\\\ n,DateTime.Now,i,*无论你想写什么文件*));

//然后在这里递增

i ++;
cant u do like
int i = 1;
and each time u write u pass it to the writeline and then increment.

something like
//have this in some method
streamwriter sw;
sw.WriteLine(String.Format("{0} \r\n {1} {2} \r\n", DateTime.Now, i, *whatever u wanna write to the file*));
//and then increment here
i++;


这篇关于在c#中写入具有自动标识no的日志(txt)文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆