Write log while creating ur application. use below two class for write a log for ur appliaciton
//**************************************************************************//
Create one Application Class for Address where to store log………….
/******************/
using System;
using System.Collections.Generic;
using System.Text;
class AppClass
{
/******************/
using System;
using System.Collections.Generic;
using System.Text;
class AppClass
{
// change folder name if require by default mylog in c drive
//public static string AppPath = @"c:\myLog\";
// public static string AppPath = System.IO.Path. GetDirectoryName(System. Reflection.Assembly. GetExecutingAssembly(). Location);
public static string AppPath = System.IO.Path. GetDirectoryName(AppDomain. CurrentDomain.BaseDirectory);
//public static string AppPath = @"c:\myLog\";
// public static string AppPath = System.IO.Path.
public static string AppPath = System.IO.Path.
public AppClass()
{
Log4NET.Write(this.ToString( ) + " AppPath " + AppPath);
}
}
{
Log4NET.Write(this.ToString(
}
}
//**************************************************************************/
// Create another Class for write log as per Datetime
using System;
using System.Collections.Generic;
using System.Text;
public class Log4NET
{
public static string logfile = @"\logs\LogEntery.log";
public static string errlogfile = @"\logs\LogError.err";
public static void Write(string message)
{
string DateTimeFile = "";
DateTime dt = DateTime.Now;
try{
if (!System.IO.Directory.Exists( AppClass.AppPath + @"\logs"))
{
System.IO.Directory. CreateDirectory(AppClass. AppPath + @"\logs");
}
DateTimeFile = dt.Year + "" + (dt.Month <= 9 ? "0" + dt.Month + "" : dt.Month + "") + "" + dt.Day + "";
logfile = @"\logs\DBConfig_" + DateTimeFile + ".log";
System.IO.FileStream fs = System.IO.File.Open(AppClass. AppPath + logfile, System.IO.FileMode.Append);
byte[] info = new System.Text.UTF8Encoding(true) .GetBytes(System.DateTime.Now. ToString() + ":" + message + "\n");
fs.Write(info, 0, info.Length);
fs.Close();
}catch(Exception se){
if (!System.IO.Directory.Exists( AppClass.AppPath + @"\logs"))
{
System.IO.Directory. CreateDirectory(AppClass. AppPath + @"\logs");
}
System.IO.FileStream fs = System.IO.File.Open(AppClass. AppPath + @"\logs\dbLogCon.err", System.IO.FileMode.Append);
byte[] info = new System.Text.UTF8Encoding(true) .GetBytes(System.DateTime.Now. ToString() + ":" + message + "\n");
fs.Write(info, 0, info.Length);
fs.Close();
}
}
public static void Error(string message)
{
string DateTimeFile = "";
DateTime dt = DateTime.Now;
try{
if (!System.IO.Directory.Exists( AppClass.AppPath + @"\logs"))
{
System.IO.Directory. CreateDirectory(AppClass. AppPath + @"\logs");
}
DateTimeFile = dt.Year + "" + (dt.Month <= 9 ? "0" + dt.Month + "" : dt.Month + "") + "" + dt.Day + "";
errlogfile = @"\logs\DBConfig_" + DateTimeFile + ".err";
System.IO.FileStream fs = System.IO.File.Open(AppClass. AppPath + errlogfile, System.IO.FileMode.Append);
byte[] info = new System.Text.UTF8Encoding(true) .GetBytes(System.DateTime.Now. ToString() + ":" + message + "\n");
fs.Write(info, 0, info.Length);
fs.Close();
}catch(Exception se){
if (!System.IO.Directory.Exists( AppClass.AppPath + @"\logs"))
{
System.IO.Directory. CreateDirectory(AppClass. AppPath + @"\logs");
}
System.IO.FileStream fs = System.IO.File.Open(AppClass. AppPath + @"\logs\dbLogCon.err", System.IO.FileMode.Append);
byte[] info = new System.Text.UTF8Encoding(true) .GetBytes(System.DateTime.Now. ToString() + ":" + message + "\n");
fs.Write(info, 0, info.Length);
fs.Close();
}
}
}
using System.Collections.Generic;
using System.Text;
public class Log4NET
{
public static string logfile = @"\logs\LogEntery.log";
public static string errlogfile = @"\logs\LogError.err";
public static void Write(string message)
{
string DateTimeFile = "";
DateTime dt = DateTime.Now;
try{
if (!System.IO.Directory.Exists(
{
System.IO.Directory.
}
DateTimeFile = dt.Year + "" + (dt.Month <= 9 ? "0" + dt.Month + "" : dt.Month + "") + "" + dt.Day + "";
logfile = @"\logs\DBConfig_" + DateTimeFile + ".log";
System.IO.FileStream fs = System.IO.File.Open(AppClass.
byte[] info = new System.Text.UTF8Encoding(true)
fs.Write(info, 0, info.Length);
fs.Close();
}catch(Exception se){
if (!System.IO.Directory.Exists(
{
System.IO.Directory.
}
System.IO.FileStream fs = System.IO.File.Open(AppClass.
byte[] info = new System.Text.UTF8Encoding(true)
fs.Write(info, 0, info.Length);
fs.Close();
}
}
public static void Error(string message)
{
string DateTimeFile = "";
DateTime dt = DateTime.Now;
try{
if (!System.IO.Directory.Exists(
{
System.IO.Directory.
}
DateTimeFile = dt.Year + "" + (dt.Month <= 9 ? "0" + dt.Month + "" : dt.Month + "") + "" + dt.Day + "";
errlogfile = @"\logs\DBConfig_" + DateTimeFile + ".err";
System.IO.FileStream fs = System.IO.File.Open(AppClass.
byte[] info = new System.Text.UTF8Encoding(true)
fs.Write(info, 0, info.Length);
fs.Close();
}catch(Exception se){
if (!System.IO.Directory.Exists(
{
System.IO.Directory.
}
System.IO.FileStream fs = System.IO.File.Open(AppClass.
byte[] info = new System.Text.UTF8Encoding(true)
fs.Write(info, 0, info.Length);
fs.Close();
}
}
}
//**********************************************************************//
//***********************how to use in ur application**************************//
protected void btnLogin_Click(object sender, EventArgs e)
{
{
Try
{
Log4NET.Write("Login Clicked:");
}
}
Catch(Exception er)
{
Log4NET.Error("Login Failed:" +er.ToString());
}
}
}
//*******************//
//File Created on above path and log is written.......
logfile
Thank you bhavesh