找不到类型或名称空间名称“ ConsoleTraceListener”是否缺少using指令或程序集引用?

问题描述

我尝试用2个文件编写C#程序:SyncService.cs和Program.cs,如下所示:

Program.cs

using System;
using System.Diagnostics;

namespace AzcopySync
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Trace.Listeners.Add(new ConsoleTraceListener());
            Trace.WriteLine("Program Started - " + DateTime.Now.ToString());Trace.WriteLine("");

            //Call into a separate class or method for the actual program logic
            //DoSomething(); //I'll use Trace for output in here rather than Console
            string source = "/home/potivora/data";
            string dest = "https://dfqualifstoracc.blob.core.windows.net/media-shutima";
            SyncService mySyncService = new SyncService();
            //mySyncService.TriggerBlobSync(source,dest);

            Console.WriteLine(mySyncService.TriggerBlobSync(source,dest));
         
            Trace.WriteLine("");Trace.WriteLine("Program Finished - " + DateTime.Now.ToString());

            Console.Write("Press a key to exit...");
            Console.ReadKey(true);
            Console.WriteLine();
        }
    }
}

SyncService.cs

using System;
using System.Diagnostics;

namespace AzcopySync
{
   public class SyncService 
   {
      const string AZcopY_SYNC_CMD = " sync \"{0}\" \"{1}{2}\" --recursive";
      const string SASToken = "?sv=2019-10-10&si=upload-images&sr=c&sig=WZ7b6EbuPNev1cGEmepuy4%2FTNKBgvZ5zqEU246KrSNs%3D";
   
      public SyncService ()
      {
      }

      public string TriggerBlobSync(string sourcePath,string destPath)
      {
         processstartinfo si = new processstartinfo("azcopy")
         {
             Arguments = string.Format(AZcopY_SYNC_CMD,sourcePath,destPath,SASToken),CreateNowindow = true,UseShellExecute = false,RedirectStandardOutput = true
         };

         Console.WriteLine(si.FileName + "" + si.Arguments);

         var process = Process.Start(si);
         return process.StandardOutput.ReadToEnd();
      }
   
   }
}

当我执行“ dotnet run”时,会收到此错误消息。

compileERR

通常我的代码已经可以通过SyncService.cs编译并正确运行。但是,我决定添加Program.cs,因为我在Internet上也看到了很多C#程序的示例,在项目中也带有Program.cs文件,即使我不确定是否需要它也是如此。所以我实际上将主要功能从SynService.cs移到Program.cs,因为我认为我应该只有1个主要功能,因为在解决此问题之前,我又遇到了另一个错误。 您能帮我指出什么可能是根本原因吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)