Click here to Skip to main content
15,909,530 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
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???
Posted
Comments
BillWoodruff 30-Dec-14 5:50am    
Not enough information here to assist you: are you writing whenever there is an error, or writing the log at some regular interval ?

Is this WinForms, WPF ?

What stops you now from having a static integer variable that keeps track of the current count of log entries and writing the value of that variable into the log ?
pradeepbliss 30-Dec-14 6:08am    
winform, i cant assign static interger variable because based upon some conidition i am writing to log file
BillWoodruff 30-Dec-14 9:13am    
I think to assist you we'll need to see some of the code you are using. Why can't you use some kind of a variable to insert an ID number into the Log ?
CLilium 30-Dec-14 9:22am    
If you are just calling and event to log to the file it would be better to make a logger class for this job. Once you have just make a private property for counting and add it into the input. As far as I know there is no auto identity in c# like in DBs.

1 solution

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++;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900