0

I'm working on creating web application, which will host in IIS, which I plan to accept a lot of short time connections. Right now I'm working on error logging, and it turns out that it's not that clear how to do it.

For example my back-end sql server went down and 1000 clients which try to get responses from server each 10 minutes, will flood in the event log of the server 60000 events in 1 hour. Can anyone share his experience on how not to flood the event log on the server?

The code is close to this:

RequestHandler :

try {
    SqlConnection con = new SqlConnection(...);
    cmd.CommandText = "SELECT TOP FROM Foo WHERE Bar = `"Some`"";
    con.Open();
    cmd.Connection = con;

    // convert data to instance
}
catch (SqlException ex)
{
    Logger.WriteErrorEvent(ex)
}
// convert instance to response and send it back.

Thanks, Jenia.

4

2 回答 2

0

您需要创建一个文件并将所有错误写入该文件,而不是记录到事件日志。类似于以下方法,您可以在遇到任何异常时调用此方法。

    public static void SaveLog(string exc)
    {

            FileStream objFS = null;


                string strFilePath = "Exception.log";
                if (!File.Exists(strFilePath))
                {
                    objFS = new FileStream(strFilePath, FileMode.Create);
                }
                else
                    objFS = new FileStream(strFilePath, FileMode.Append);

                using (StreamWriter Sr = new StreamWriter(objFS))
                {
                    Sr.WriteLine(System.DateTime.Now.ToShortTimeString() + "---" + exc);
                }


    }
于 2013-08-01T04:01:20.243 回答
0

正如在另一篇文章中一样 - 最好的解决方案是使用您自己的文件进行日志记录。我建议为此使用log4net。开始需要一段时间,但一旦你学会了它,你就会看到它有多么有用。它将允许您设置不同的日志记录级别,这样您就可以只记录您当时需要的信息并即时更改它们。

于 2013-08-01T04:15:58.430 回答