Click here to Skip to main content
15,511,274 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello everybody,
I have an application that converts excel_to_db and db_to_excel.I want to generate log files to my application in a text format i.e into errorlog.txt file help me for the solution.




Thanks & Regards,
srinath.pothineni
Posted
Comments
Swinkaran 23-Aug-12 20:02pm    
Do you want a simple log file like a txt. or do you need a proper log file which shows the time of the error, format and also the line of the code where the error occured?
Swinkaran 24-Aug-12 0:31am    
The better approach for logging error & process is to use Log4Net.
see this link http://logging.apache.org/log4net/
I am using this in my applications. very useful tool by Apache. Thanks.

You know the details of your code, and what you want to log. Server.MapPath("/App_Data") will give you a file system path to one place you could write this. System.IO.File.WriteAllText is the easiest way to write the text of the log you create.
 
Share this answer
 
 
Share this answer
 
Are you using a 3rd paty application to convert. If yes, then you have no choice to log error.

If the application is written by you, the it is pretty straight forward to log your error.

In the code where you are transferring data to another database, by insert statement, you need to trap the catch exception. Any error, you need to update the log text file.

try{
  //your code - inserting/updating data or bulk insert/update
}
catch(SqlException ex){
  //create error log
  //take the detail exception string from ex and generate a string with other details you want and send it to a text file.
}


Hope this help.
cheers
 
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