Visual Studio for Mac:日志在一个项目上工作并显示在Azure上,但在相同解决方案的另一个项目上失败

che*_*der 7 c# azure circular-reference nuget visual-studio-mac

在解决方案的主要项目中,我有:

public static void Main(string[] args)
{
    // Testing Logs on Azure Application Insights: 
    var telemetry = new Microsoft.ApplicationInsights.TelemetryClient();
    telemetry.TrackTrace("Test of ApplicationInsights.TelemetryClient() on Program.cs");

    CreateWebHostBuilder(args).Build().Run();     
}
Run Code Online (Sandbox Code Playgroud)

它正在工作,并且日志正在Azure应用程序见解中显示。

不幸的是,当我将相同的代码添加到相同解决方案的另一个项目中时,它不起作用:而是在Azure上引发异常。

我尝试添加对主项目的引用(因为我认为这将导入其项目和其他所需的内容)。不幸的是我不能,因为它说:

不允许循环依赖

因此,我在解决方案的其他项目中添加了相同的细节。这样,它便可以编译,并且我可以上传到Azure。但是由于该错误,我看不到日志(跟踪):

Azure屏幕截图

在Azure上显示的日志的文本版本(Trace):

AI (Internal): [Microsoft-ApplicationInsights-AspNetCore-StartupBootstrapper] Could not load Microsoft.AspNetCore.ApplicationInsights.HostingStartup. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.ApplicationInsights.HostingStartup, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
File name: 'Microsoft.AspNetCore.ApplicationInsights.HostingStartup, Culture=neutral, PublicKeyToken=null'
   at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, IntPtr ptrLoadContextBinder)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, IntPtr ptrLoadContextBinder)
   at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, StackCrawlMark& stackMark, IntPtr pPrivHostBinder)
   at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, StackCrawlMark& stackMark)
   at System.Reflection.Assembly.Load(String assemblyString)
   at Microsoft.ApplicationInsights.AssemblyLoader.Load(String assemblyName)
   at StartupBootstrapper.Startup.TryLoadStartupAssembly(String assemblyName)
Run Code Online (Sandbox Code Playgroud)

我使用的是Visual Studio for Mac(又名VS for mac 2019)。注意,它实际上与Windows的Visual Studio不同:使用Windows的Visual Studio在Azure上调试要容易得多!

我究竟做错了什么?

Ada*_*zak 0

尝试通过 nuget 包管理器或 dotnet cli 命令将包添加到项目中

dotnet add package Microsoft.ApplicationInsights --version 2.10.0
Run Code Online (Sandbox Code Playgroud)

如果已安装,请尝试重新安装并更新至最新版本