コミュニティApplication Insight with ASP APIコアを使用する
私のASP WEB APIコアにApplication Insightを接続する際に問題が発生しています。 標準のマニュアルに従って、私はまだAppInsightsアカウントでレコードを見つけることができません。 私は多くのマニュアルを使用しましたが、かなり同じで、ASPコア(APIコアではない)のためのApp Insightの設定方法を説明しています。 AppInsightsのリクエストをAPIサービスに追跡させるためには、特別な設定(または、ナゲットパッケージなど)が必要なのでしょうか?
AppInsightsをすぐに使えないようにしても、TelemetryClientのインスタンスを作成して手動でデータを公開することはできますが、これは私の場合は望ましくありません。
重要な注意:私はVS 2017 RC、Web APIをコアプロジェクト(csproj)
UPD
csprojファイルの内容を使用しています:Startup.csで
<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.0</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>
<ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="1.0.0-msbuild1-update1" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0-msbuild1-final" />
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="1.0.0-msbuild2-update1" />
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="1.0.0-msbuild1-update1" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0-msbuild1-final" />
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="1.0.0-msbuild2-update1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="1.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.0.1" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.2.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0-msbuild1-final" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="1.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.0.0-msbuild2-final" />
<PackageReference Include="Microsoft.NETCore.App" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Https" Version="1.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="Swashbuckle.SwaggerGen" Version="6.0.0-beta901" />
<PackageReference Include="Swashbuckle.SwaggerUi" Version="6.0.0-beta901" />
</ItemGroup>
</Project>
構成:
public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
if (env.IsDevelopment())
{
// This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
builder.AddApplicationInsightsSettings(true);
}
builder.AddEnvironmentVariables();
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddApplicationInsightsTelemetry(Configuration);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug(LogLevel.Trace);
loggerFactory.AddConsole(LogLevel.Error);
app.UseApplicationInsightsExceptionTelemetry();
app.UseMvc();
}
ただFYI:ASP.NET Web APIコアなどはありません。 MVCとWeb APIがASP.NET Core MVCに統合されました。ロギングとcsprojファイルでいくつかのコードを表示できますか? –