Skip to content

Instantly share code, notes, and snippets.

@antoantonyk
Created December 15, 2018 14:37
Show Gist options
  • Save antoantonyk/4ea9c654ac4b0f653ee156eb192efa56 to your computer and use it in GitHub Desktop.
Save antoantonyk/4ea9c654ac4b0f653ee156eb192efa56 to your computer and use it in GitHub Desktop.
string logFile = "log-" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
string filePath = WebConfigurationManager.AppSettings["LogPath"].ToString();
//example --- c:/website/Logs/
if (!string.IsNullOrEmpty(filePath))
{
FileInfo fileInfo = new FileInfo(filePath);
if (!fileInfo.Exists)
Directory.CreateDirectory(filePath);
using (StreamWriter writer = new StreamWriter(filePath + logFile, true))
{
writer.WriteLine("IpAddress :" + ipAddress + "<br/>" + Environment.NewLine +
"" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment