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

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();
}

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

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

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



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

c# - Visual Studio for Mac : Logs work on a Project and are shown on Azure,,但是在相同解决方案的另一个项目上失败-LMLPHP

在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)

我使用的是Visual Studio for Mac(又名VS for mac 2019)。请注意,它实际上与Windows的Visual Studio不同:it's much easier to Debug on Azure using Visual Studio for Windows!

我究竟做错了什么?

最佳答案

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

dotnet add package Microsoft.ApplicationInsights --version 2.10.0

如果已经安装,请尝试重新安装并获取最新信息

关于c# - Visual Studio for Mac : Logs work on a Project and are shown on Azure,,但是在相同解决方案的另一个项目上失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57540016/

10-12 22:34
查看更多