使用web应用程序将错误消息记录在客户端的日志文件中

本文关键字:客户端 日志 文件 记录 应用程序 web 错误 消息 使用 | 更新日期: 2023-09-27 18:24:47

我的应用程序是Mvc4 web应用程序我正在阅读一个可能有20000条记录的excel文件循环将遍历整个excel文件,并将所有有错误的行添加到字符串生成器对象中,用户稍后应该能够在文件中更正这些行。我的用户希望将其显示在一个文本文件中,就像他们可以立即看到的日志文件一样。我现在正在div中显示这一点,但担心当他们遇到了很多错误

问:我如何将所有这些错误记录在一个文本文件中,我的用户可以点击该文件并在客户端上查看有错误的行。

请注意,多个用户可以使用此web应用程序。

                    StringBuilder sb = new StringBuilder();
                    for (int rowNumber = startRow + 1; rowNumber <= currentWorkSheet.Dimension.End.Row; rowNumber++)
                            // read each row from the start of the data (start row + 1 header row) to the end of the spreadsheet.
                    {
                        try
                        {
                            object col1Value = currentWorkSheet.Cells[rowNumber, 1].Value;
                            object col2Value = currentWorkSheet.Cells[rowNumber, 2].Value;
                            object col3Value = currentWorkSheet.Cells[rowNumber, 3].Value;
                            object col4Value = currentWorkSheet.Cells[rowNumber, 4].Value;
                            if ((col1Value != null && col2Value != null))
                            {
                                exampleDataList.Add(new PersonalData
                                {
                                    firstname = col1Value.ToString(),
                                    lastname = col2Value.ToString(),
                                    currentDate = col3Value == null ? DateTime.MinValue : Convert.ToDateTime(col3Value),
                                    mySalary = col4Value == null ? 0 : Convert.ToInt32(col4Value)
                                });
                            }
                        }      
                        catch (Exception e)
                        {
                             //log exception here
                            sb.AppendFormat("{0}: {1}{2}",rowNumber, e.Message, Environment.NewLine);           
                        }
                    } 
                    //convert the StringBuilder into the final string object
                    string allMessages = sb.ToString();

使用web应用程序将错误消息记录在客户端的日志文件中

也许像Log4Net这样的东西就足够满足您的需求了。最后,您甚至可以提供一个UI来处理应用程序中的这些有问题的条目。

那么,为什么不将它们存储在数据库中,然后在自定义UI中显示,用户可以在其中以协作的方式逐一处理问题呢?