how to save exception in txt file?

前端 未结 5 1133
逝去的感伤
逝去的感伤 2021-01-31 16:46
public DataTable InsertItemDetails(FeedRetailPL objFeedRetPL)
{
    DataTable GetListID = new DataTable();
    try
    {
        SqlParameter[] arParams = new SqlParamet         


        
5条回答
  •  借酒劲吻你
    2021-01-31 17:28

    string[] path1 = Directory.GetFiles(@"E:\storage", "*.txt");//it get the all textfiles from the folder

                    for (var i = 0; i < path1.Length; i++)
                    {
                    var file = Directory.GetDirectories(networkPath);
    
                    
    
                        var path = file;
                    string temp_FilePath = "E:\\temp.txt";
                    string temp_FilePath1 = @"E:\ExceptionFiles\Cs_regular\\Cs_regular.txt";
                    string temp_FilePath2 = @"E:\ExceptionFiles\CC_eBilling\\CC_eBilling.txt";
                    string folder = @"E:\ExceptionFiles\Cs_regular";
                    string folder1 = @"E:\ExceptionFiles\CC_eBilling";
    
    
    
                    string[] lines;
                    var list = new List();
                    var list1 = new List();
                    var list2 = new List();
                    var error = false;
                    var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
                    var fileStream1 = new FileStream(path, FileMode.Open, FileAccess.Read);
                    var fileStream2 = new FileStream(path, FileMode.Open, FileAccess.Read);
    
    
    
    
                    using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
                    {
                        string line;
    
    
    
                        while ((line = streamReader.ReadLine()) != null)
                        {
    
    
                            var res = line.Substring(20, 16);
                            //var timenow = DateTime.Now.ToString("yyyy /MM/dd HH:mm");
                            var timenow1 = "2020/10/31 10:11";
    
                            if (res == timenow1)
                            {
    
                                string linesRemoved = "ERROR";
    
                                if (!line.Contains(linesRemoved))
                                {
    
                                    if (error == true)
                                    {
                                        if (line.Contains("at"))
                                        {
                                            list1.Add(line);
                                            error = true;
                                        }
                                        else
                                        {
                                            error = false;
                                        }
                                    }
    
                                }
                                else
                                {
                                    error = false;
                                }
    
    
    
    
                                if (line.Contains("Exception1") && error == false)
                                {
                                    list1.Add(line);
                                    error = true;
                                }
    
                            }
    
    
    
                        }
                    }
    
                    
    
                    using (var streamReader2 = new StreamReader(fileStream2, Encoding.UTF8))
                    {
                        string line;
                        while ((line = streamReader2.ReadLine()) != null)
                        {
                            string linesRemoved = "ERROR";
                            var res = line.Substring(20, 16);
                            //var timenow = DateTime.Now.ToString("yyyy/MM/dd HH:mm");
                            var timenow1 = "2020/10/29 12:38";
                            if (res == timenow1)
                            {
    
                                if (!line.Contains(linesRemoved))
                                {
                                    if (error == true)
                                    {
                                        if (line.Contains("at"))
                                        {
    
                                            list2.Add(line);
                                            error = true;
                                        }
                                        else
                                        {
                                            error = false;
                                        }
                                    }
                                }
                                else
                                {
                                    error = false;
                                }
    
    
    
                                if ((line.Contains("Exception2") && line.Contains("Exception:")) && error == false)
                                {
                                    list2.Add(line);
                                    error = true;
    
                                }
                            }
    
    
    
    
    
    
                        }
                    }
    
    
    
    
                    if ((System.IO.File.Exists(temp_FilePath1) || System.IO.File.Exists(temp_FilePath2)))
                    {
    
                        int fileCount = Directory.GetFiles(folder).Length;
                        int fileCount1 = Directory.GetFiles(folder1).Length;
                        fileCount++;
                        fileCount1++;
                        temp_FilePath1 = temp_FilePath1 + "(" + fileCount.ToString() + ").txt";
                        temp_FilePath2 = temp_FilePath2 + "(" + fileCount1.ToString() + ").txt";
    
    
                    }
                    {
                        System.IO.File.WriteAllLines(temp_FilePath1, list1);
                        System.IO.File.WriteAllLines(temp_FilePath2, list2);
    
                    }
    
    
    
    
    
                    System.IO.File.WriteAllLines(temp_FilePath, list);
    
                    System.IO.File.WriteAllLines(temp_FilePath1, list1);
                    System.IO.File.WriteAllLines(temp_FilePath2, list2);
    
                    }
    
                }
            }
            catch (Exception ex)
            {
    
            }
    
    
    
            return null;
    

提交回复
热议问题