1. Logging in ExceptionLogging.cs
public static void Threeparameter(string req, string res, string rest)
{
var line = Environment.NewLine + Environment.NewLine;
try
{
string filepath = HttpContext.Current.Server.MapPath("~/testor/"); // Text File Path
if (!Directory.Exists(filepath))
{
Directory.CreateDirectory(filepath);
}
filepath = filepath + DateTime.Today.ToString("dd-MM-yy") + ".txt"; // Text File Name
if (!File.Exists(filepath))
{
File.Create(filepath).Dispose();
}
using (StreamWriter sw = File.AppendText(filepath))
{
string message = string.Format("Time: {0}", DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt"));
message += Environment.NewLine;
message += "--------------------------API URL---------------------------------";
message += Environment.NewLine;
message += string.Format("{0}", rest);
message += Environment.NewLine;
message += "--------------------------Request Parameter---------------------------------";
message += Environment.NewLine;
message += string.Format("{0}", req);
message += Environment.NewLine;
message += Environment.NewLine;
message += "--------------------------Response Parameter---------------------------------";
message += Environment.NewLine;
message += string.Format("{0}", res);
message += Environment.NewLine;
sw.WriteLine(message);
sw.Flush();
sw.Close();
}
}
catch (Exception e)
{
e.ToString();
}
}
public static void singleparamter(string resp)
{
var line = Environment.NewLine + Environment.NewLine;
try
{
string filepath = HttpContext.Current.Server.MapPath("~/testing/"); // Text File Path
if (!Directory.Exists(filepath))
{
Directory.CreateDirectory(filepath);
}
filepath = filepath + "IPOMaster" + DateTime.Today.ToString("dd-MM-yy") + ".txt"; // Text File Name
if (!File.Exists(filepath))
{
File.Create(filepath).Dispose();
}
using (StreamWriter sw = File.AppendText(filepath))
{
string message = Environment.NewLine;
message += "DataTime: " + DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss tt") + ", " + resp;
message += Environment.NewLine;
sw.WriteLine(message);
sw.Flush();
sw.Close();
}
}
catch (Exception e)
{
e.ToString();
}
}
Log Content
- API URL
- Request Parameter
- Response Parameter
How to call the log?
Threeparameter("req value", "response value", "text");
singleparamter("Closed IPO");
File Name Format
DateTime.Today.ToString("dd-MM-yy") + ".txt";
2. Logging in iservices.svc.cs
public void WriteLog(string log)
{
try
{
string filepath = System.Web.Hosting.HostingEnvironment.MapPath("~/folder/subfolder/");
if (!Directory.Exists(filepath))
{
Directory.CreateDirectory(filepath);
}
StreamWriter sw = new StreamWriter(filepath + DateTime.Now.ToString("ddMMyy") + ".txt", true);
sw.WriteLine(DateTime.Now.ToString() + " " + log);
sw.WriteLine("---------------------------------------------------------------------------------------------------------");
sw.Close();
}
catch (Exception ex)
{
string str = ex.ToString();
}
}
3. Logging CSV in Executable
Location
source + "/File/"
File Name Format
"Face_" + DateTime.Now.ToString("ddMMyyyy_HHmm") + ".csv"
Purpose: To save data (probably biometric/face recognition data) in CSV format.
Key Features
- Not a standard log, but structured data storage.
- Ensures unique filenames with date + time format.
- UTF-8 encoding ensures compatibility.
Summary Table
Logging Type |
File Name Pattern |
Log Folder Path |
Log Content Type |
Context |
(Web) |
dd-MM-yy.txt |
~/foldername/ |
API URL, Request, Response |
Web – Request Flow |
(Web) |
filenamedd-MM-yy.txt |
~/foldername/ |
Only Response |
Web – IPO Logs |
(iservices.svc) |
ddMMyy.txt |
~/foldername/subfoldername/ |
Single-line logs with a delimiter |
Web Services |
(.exe) |
filename-MM-yy.txt |
/foldername/ |
Timestamp + Response |
Executable Component |
CSV Export (.exe) |
filename_ddMMyyyy_HHmm.csv |
/foldername/ |
Structured CSV data |
Desktop Biometric Logs |
Conclusion
Each logging method serves a unique purpose, depending on the module (Web or Executable) and type of data being logged (API flows, exceptions, biometric logs). This modular logging approach helps in efficient debugging, system auditing, and API behavior tracking.