写入日志文件c#

aro*_*isa 0 c# xml logfile

我有一个代码,我从XML文件中读取一个我必须保存结果的路径,如果程序中出现错误并停止,请记下错误.

我的程序有这样的结构:

namespace RiskFactorListUpdater
{
    public static class Program
    {
       public static void Main(string[] args)
        {
            try
            {
                //get the data
                filename=.....;
                // blah blah blah


                // more code

              }catch(Exception e)
               {
                //write in log file
             }
Run Code Online (Sandbox Code Playgroud)

当我尝试读取文件名的路径时出现问题.我无法在捕获"部分"中阅读它.我是c#的新手.这样做有简单的方法吗?

提前致谢

Jer*_*iel 5

catch块之前声明要在块中使用的任何内容try.

public static class Program
{
   public static void Main(string[] args)
    {
        string filename;
        try
        {
            //get the data
            filename=.....;
            // blah blah blah


            // more code

          }catch(Exception e)
           {
            //write in log file
         }
Run Code Online (Sandbox Code Playgroud)