logging.cs
1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
namespace AIAHTML5.WebAPI.Util
{
public class logging
{
#region Logs
internal void logData(string Msg)
{
string filepath = System.Web.HttpContext.Current.Server.MapPath("~/LogDetailsFile/"); //Text File Path
if (!Directory.Exists(filepath))
{
Directory.CreateDirectory(filepath);
}
filepath = filepath + DateTime.Today.ToString("dd-MM-yy") + ".txt"; //Text File Name
if (!System.IO.File.Exists(filepath))
{
System.IO.File.Create(filepath).Dispose();
}
using (StreamWriter sw = System.IO.File.AppendText(filepath))
{
string error = "Log Written Date:" + " " + DateTime.Now.ToString();// +line + "Error Line No :" + " " + ErrorlineNo + line + "Error Message:" + " " + Errormsg + line + "Exception Type:" + " " + extype + line + "Error Location :" + " " + ErrorLocation + line + " Error Page Url:" + " " + exurl + line + "User Host IP:" + " " + hostIp + line;
// sw.WriteLine("-----------Log Written Date: " + " " + DateTime.Now.ToString() + "-----------------");
sw.WriteLine("-------------------------------------------------------------------------------------");
// sw.WriteLine(line);
sw.WriteLine(Msg);
// sw.WriteLine("--------------------------------*End*------------------------------------------");
// sw.WriteLine(line);
sw.Flush();
sw.Close();
}
}
#endregion
}
}