如何解决找不到类型或名称空间名称“ 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”时,会收到此错误消息。
通常我的代码已经可以通过SyncService.cs编译并正确运行。但是,我决定添加Program.cs,因为我在Internet上也看到了很多C#程序的示例,在项目中也带有Program.cs文件,即使我不确定是否需要它也是如此。所以我实际上将主要功能从SynService.cs移到Program.cs,因为我认为我应该只有1个主要功能,因为在解决此问题之前,我又遇到了另一个错误。 您能帮我指出什么可能是根本原因吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。