logging.cs 1.71 KB
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
    }
}