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
16 comments:
I seldom leave comments on blog, but I have been to this post which was recommended by my friend, lots of valuable details, thanks again.
a new thing arrives
Http://www.songsquery.com
It is my pleasure to say you that all of your articles are superb and I really love the way you put each and every sentence. You will be rated 8.75 out of 10. Brilliant work,keep it up. Your grammatical sense is simply outstanding. Carry on the good work.And yes i have bookmarked your site sqlclass3.blogspot.com .
Thanks for taking the time to discuss this, I really feel strongly about it and love learning more on this topic. If potential, as you achieve expertise, would you thoughts updating your blog with additional data? It is extremely helpful for me.
Need to keep testing my blog. Not working as I want it to yet. Thanks for the theme. Maybe this will get mine to look better.
tramadol online no prescription where to buy tramadol online - tramadol dosage people
buy tramadol online tramadol online no prescription overnight delivery - high on tramadol hcl
buy tramadol online tramadol hcl 50 mg and tylenol - how to buy tramadol online overnight
xanax online generic xanax pills identification - xanax cures anxiety
cheap tramadol tramadol 50mg how many can i take - tramadol depression
tramadol generic tramadol addiction how long - tramadol vs codeine high
xanax pills xanax bars in system - buy cheap xanax online with no prescription
buy cheap tramadol tramadol 50 mg for dogs - buy tramadol ultram
xanax online interaction of xanax and alcohol - xanax online to australia
buy tramadol online can dog overdose tramadol - tramadol withdrawal duration symptoms
buy tramadol online no prescription overnight tramadol dosage feline - tramadol hcl 300 mg
Post a Comment