我按照此页面Application Insights 说明将 Application Insights (AI) 添加到我的 Web API 服务。我设法让我的服务连接到人工智能,并且我能够看到我的服务何时执行发布、获取等。我还通过我的服务发出了日志调用,但它们都没有写入我的人工智能的跟踪日志。
我确保设置 Startup.cs 和 appsettings.json 文件以包含在整个服务中运行 AI 所需的新代码,并且日志数据需要让 AI 抓取日志进行调试和启动。
启动.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddApplicationInsightsTelemetry();
}
Run Code Online (Sandbox Code Playgroud)
应用程序设置.json
记录示例
public async Task ProcessQueueAsync(dBData dbContext)
{
// _logger is of type ILogger<[INSERT CLASS NAME]>
_logger.LogDebug("This is a test log by Lotzi11.");
await ProcessQueueAsyncSingle(dbContext, CancellationToken.None);
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮我弄清楚为什么我的日志没有发送到人工智能吗?
我必须更新存储为 Azure blob 的大文件。此更新将需要几秒钟,我需要确保没有其他客户端获得部分更新的文件。
如https://docs.microsoft.com/en-us/azure/storage/common/storage-concurrency 中所述,锁定文件进行写入应该很容易,但据我所知,其他客户端仍然可以读取文件。我可以使用读锁,但这意味着只有一个客户端可以读取文件,这不是我想要的。
根据防止 azure blob 在创建时被其他服务访问,似乎至少会在上传结束时“提交”新文件,但我找不到更新现有文件时会发生什么的信息。
所以,问题是:在更新(替换)操作期间其他客户端会读取什么?
我想在 C# 控制台应用程序中读取 AppInsights API 输出。
WebClient wc = new WebClient();
wc.BaseAddress = "https://api.applicationinsights.io/v1/apps/AppInsighID/query?query=requests|where timestamp>= ago(1h)|limit 100";
wc.Headers.Add("Host", "api.applicationinsights.io");
wc.Headers.Add("x-api-key", "key");
string json = wc.DownloadString("");
JObject jsonObject = JObject.Parse(json);
//With this, i got values for Rows
var rowsObject = jsonObject["tables"][0]["rows"];
Run Code Online (Sandbox Code Playgroud)
现在值在数组中,在 rowObject 下,那么如何读取呢?
我也想知道在阅读 json 字符串时我们应该遵循的最佳实践
我可以看到这样的数据
{
"tables": [
{
"name": "PrimaryResult",
"columns": [
{
"name": "timestamp",
"type": "datetime"
},
{
"name": "id",
"type": "string"
},
{
"name": "source",
"type": "string"
},
{
"name": "name",
"type": "string"
},
{ …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序设置为使用 Application Insights,并且我正在尝试手动记录一些自定义信息。这是我的控制器:
public class MyController : Controller
{
private ILogger<MyController> Logger { get; set; }
public MyController(ILogger<MyController> logger)
{
Logger = logger;
}
public IActionResult Index()
{
Logger.LogCritical("Test critical");
Logger.LogError("Test error");
Logger.LogWarning("Test warning");
Logger.LogInformation("Test information");
Logger.LogDebug("Test debug");
Logger.LogTrace("Test trace");
...
}
Run Code Online (Sandbox Code Playgroud)
我的 Startup.cs 中有这个:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Warning);
...
Run Code Online (Sandbox Code Playgroud)
}
这在我的 Program.cs 中:
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseApplicationInsights()
.UseStartup<Startup>()
.Build();
Run Code Online (Sandbox Code Playgroud)
在我的 appsettings.json 中:
"Logging": {
"IncludeScopes": false, …Run Code Online (Sandbox Code Playgroud) 我正在尝试记录我的 ASP.NET Core 应用程序的信息,但我找不到在 Azure 日志流中显示 loogs 的方法。当我在 Visual Studio 中调试时,应用程序成功记录日志,但在发布到 Azure 时看不到任何内容。
这是我的应用服务日志的样子: 应用服务日志
我尝试使用我在 Microsoft 文档中找到的不同方法进行登录,但都没有奏效。
[HttpGet]
public string Index()
{
Trace.TraceInformation("You are in the face recognition controller. Trace");
_logger.LogInformation("You are in the face recognition controller. Logger");
return "You are in the face recognition controller";
}
Run Code Online (Sandbox Code Playgroud)
控制器构造函数:
private readonly ILogger _logger;
public FaceRecognitionController(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<FaceRecognitionController>();
}
Run Code Online (Sandbox Code Playgroud)
配置方法:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
loggerFactory.CreateLogger("console");
loggerFactory.CreateLogger("debug");
app.UseHttpsRedirection();
app.UseRouting(); …Run Code Online (Sandbox Code Playgroud) 在asp.net的服务中,我们可以为应用程序洞察设置cloud_rolename。使用此功能,我们的服务团队可以跟踪应用程序洞察中的错误。我如何从角度设置它。这就是我以角度运行应用程序洞察的方式:
export class MonitoringService {
private appInsights: ApplicationInsights;
constructor(private router: Router) {
this.appInsights = new ApplicationInsights({
config: {
instrumentationKey: environment.appInsights.instrumentationKey,
},
});
this.appInsights.loadAppInsights();
this.loadCustomTelemetryProperties();
this.createRouterSubscription();
Run Code Online (Sandbox Code Playgroud)
}
我对 Azure Application Insight 完全陌生,并尝试通过我的本地计算机发送 TrackEvent。但Azure Application Insight似乎没有收到任何信息。
这是我的要求。规格 我安装了 application Insight sdk nuget 的示例 asp.net 框架控制台代码是使用遥测客户端和配置的 Instrumental Id 进行设置的。控制台运行后,Azure 应用程序洞察应按预期显示历史记录。但它没有显示任何东西。我错过了什么吗?
我的简单控制台代码
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.InstrumentationKey = "c453fec7-ea68-4c06-83e4-2938eef1f124";
TelemetryClient telemetry = new TelemetryClient();
telemetry.Context.User.Id = "Test User Id.";
telemetry.Context.User.Id = "Test Device Id.";
telemetry.TrackEvent("Test TrackEvent");
Run Code Online (Sandbox Code Playgroud)
InstrumentationKey 正确。Telemetry.TractEvent 方法不会公开异常。Azure Application Insight 搜索(针对自定义事件)不显示历史记录。
谢谢。
我正在使用 ApplicationInsights.WorkerService nuget 包构建 .Net Core 后台服务。有关采样配置的文档表示请参考此: https: //learn.microsoft.com/en-us/azure/azure-monitor/app/sampling#configure-sampling-settings
它显示了这一点:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, TelemetryConfiguration configuration)
{
var builder = configuration.DefaultTelemetrySink.TelemetryProcessorChainBuilder;
// For older versions of the Application Insights SDK, use the following line instead:
// var builder = configuration.TelemetryProcessorChainBuilder;
// Using adaptive sampling
builder.UseAdaptiveSampling(maxTelemetryItemsPerSecond:5);
// Alternately, the following configures adaptive sampling with 5 items per second, and also excludes DependencyTelemetry from being subject to sampling.
// builder.UseAdaptiveSampling(maxTelemetryItemsPerSecond:5, excludedTypes: "Dependency");
// If you have other telemetry processors:
builder.Use((next) …Run Code Online (Sandbox Code Playgroud) 我正在尝试将异常从在Azure 应用程序服务中运行的Python 应用程序发送到指定的Azure Application Insights实例。我正在使用OpenCensus python 库来实现此目的。基本日志记录和异常已成功到达 App Insight。
除此之外,我想知道是否有一种方法可以配置异常属性,例如:problemId或任何其他属性显式地反映特定值以便更容易发出警报(例如根据 ProblemId 向特定组发送电子邮件)。
任何建议/指示都会非常有帮助
python azure-application-insights opencensus azure-appservice