C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » C# Syntax »

Write error in file


Posted Date: 28 Sep 2009    Resource Type: Code Snippets    Category: C# Syntax
Author: Kritika YadavMember Level: Gold    
Rating: 1 out of 5Points: 7



Write Error in file


Using this C# code we can write errors to files.

Create class for write error message to file

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

/// Summary description for clsErrorDisplay

public class clsErrorDisplay
{
public void WriteToFile(string ErrStr,string Page)
{
string FilePath = System.Web.HttpContext.Current.Server.MapPath("~/log/error.txt");//Add your path here

if (File.Exists(FilePath))
{
FileStream fs = new FileStream(FilePath, FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter m_streamWriter = new StreamWriter(fs);
// Write to the file using StreamWriter class
m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
m_streamWriter.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString());
m_streamWriter.WriteLine("\n"+Page + "\n");
m_streamWriter.WriteLine(ErrStr + "\n");
m_streamWriter.WriteLine("--------------------------------- \n ");
m_streamWriter.Flush();
m_streamWriter.Dispose();
fs.Close();
}
}
}


Call WriteToFile() from your form...
object.WriteToFile(ex.ToString(), Page.ToString());



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Write  .  File  .  Error  .  .net  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: ConsoleDataBaseConnectivity
Previous Resource: Working with Delegates
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use