简体   繁体   English

我们如何在服务器上捕获 c# 中的错误

[英]How can we catch an error in c# on the server

So I have here a working code in my local machine.所以我在我的本地机器上有一个工作代码。

What does is do is it will rename today's textfile.所做的就是重命名今天的文本文件。

Path小路

E:\\Rename E:\\重命名

Textfiles:文本文件:

WithdrawalConfirm20200305.txt提款确认20200305.txt

paymentpagecalls20200223.txt Paymentpagecalls20200223.txt

Output:输出:

WithdrawalConfirm20200305.1400.txt提款确认20200305.1400.txt

paymentpagecalls20200223.1400.txt paymentpagecalls20200223.1400.txt

where .XXXX is the time you run the program.其中 .XXXX 是您运行程序的时间。


 public Form1()
        {
            InitializeComponent();
        }

            string dateandtimevar = System.DateTime.Now.ToString("HHmm");

        private void Form1_Load(object sender, EventArgs e)
        {

                string FolderPath = @"E:\Rename";
                DirectoryInfo di = new DirectoryInfo(FolderPath);

                var files = di.EnumerateFiles($"*{DateTime.Now.ToString("yyyyMMdd")}.txt")
                .ToList();



                foreach (var file in files)
                {

                    //Parsing files
                    var newFile = file.FullName.Substring(0, file.FullName.Length - 3);


                    // Append new date
                    newFile = newFile + DateTime.Now.ToString("HHmm") + ".txt";

                    //Rename
                    File.Move(file.FullName, newFile);

Now my problem is when deploying to win 2008 R2 server it doesn't show any errors but it won't rename the text file like it does on my local machine.现在我的问题是在部署到win 2008 R2 server它没有显示任何错误,但它不会像在我的本地机器上那样重命名文本文件。 What could be wrong ?有什么问题?

I already checked the file path and the file exist on the server.我已经检查了文件路径并且该文件存在于服务器上。

You should check the file extension of the file and make sure if it is .txt if not change it in your desired extension.您应该检查文件的文件扩展名,并确保它是否为.txt如果没有更改为您想要的扩展名。

For example:例如:

var files = di.EnumerateFiles($"*{DateTime.Now.ToString("yyyyMMdd")}.log")
newFile = newFile + DateTime.Now.ToString("HHmm") + ".log";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM