当我单击按钮时,它必须在单击日志文件中更新 [英] When I Click On Button It Has To Update In Log File as clicked
本文介绍了当我单击按钮时,它必须在单击日志文件中更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我需要在asp.net中创建日志文件的代码,但场景是
我在网页上有一个按钮,当我点击按钮时,它必须保存为点击日志文件。
如果我每次必须保存为'n'次点击(假设如果我点击按钮10次,那么日志文件也必须更新,点击10次)。
我是.NET新手。
请做必要的....
先谢谢你...
Hi All,
I need code for creating a log file in asp.net but scenario is
I have a button in webpage when i click on the button it has to be saved as clicked in Log file.
If i click 'n' number of times every time it has to save as clicked(suppose if i click the button for 10 times it log file also it has to update as clicked for 10 times).
I am new to .NET.
please do the needful....
Thanks in Advance...
推荐答案
您可以使用类System.Diagnostics.EventLog
或第三方产品:Apache log4net:
https://msdn.microsoft.com/en-us/library/system。 diagnostics.eventlog%28v = vs.110%29.aspx [ ^ ],
https://logging.apache.org/log4net [ ^ ]。
-SA
You can use the classSystem.Diagnostics.EventLog
or 3rd-party product: Apache log4net:
https://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog%28v=vs.110%29.aspx[^],
https://logging.apache.org/log4net[^].
—SA
我尝试了下面的代码
public void WriteLog(string strLog)
{
StreamWriter日志;
FileStream fileStream = null;
DirectoryInfo logDirInfo = null;
FileInfo logFileInfo;
string logFilePath =C:\\Logs\\;
logFilePath = logFilePath +Log- + System.DateTime.Today.ToString(MM-dd-yyyy)+。 +txt;
logFileInfo = new FileInfo(logFilePath);
logDirInfo = new DirectoryInfo(logFileInfo.DirectoryName);
if(! logDirInfo.Exists)logDirInfo.Create();
if(!logFileInfo.Exists)
{
fileStream = logFileInfo.Create();
}
else
{
fileStream = new FileStream(logFilePath,FileMode.Append);
}
log = new StreamWriter(fileStream);
log.WriteLine(strLog);
log.Close() ;
}
protected void Button1_Click(对象发送者,EventArgs e)
{
logfile logfd = new logfile();
logfd.WriteLog(欢迎来到日志文件);
保存消息后我需要在消息旁保存日期
请帮帮我...
I tried the below code
public void WriteLog(string strLog)
{
StreamWriter log;
FileStream fileStream = null;
DirectoryInfo logDirInfo = null;
FileInfo logFileInfo;
string logFilePath = "C:\\Logs\\";
logFilePath = logFilePath + "Log-" + System.DateTime.Today.ToString("MM-dd-yyyy") + "." + "txt";
logFileInfo = new FileInfo(logFilePath);
logDirInfo = new DirectoryInfo(logFileInfo.DirectoryName);
if (!logDirInfo.Exists) logDirInfo.Create();
if (!logFileInfo.Exists)
{
fileStream = logFileInfo.Create();
}
else
{
fileStream = new FileStream(logFilePath, FileMode.Append);
}
log = new StreamWriter(fileStream);
log.WriteLine(strLog);
log.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
logfile logfd = new logfile();
logfd.WriteLog("Hi, welcome to log file");
After saving message i need to save date beside message
please help me...
这篇关于当我单击按钮时,它必须在单击日志文件中更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文