在一定的保留期限之后,我需要一些存档清理代码来删除旧的Azure日志。
我知道我可以这样做:
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("");
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("ctr");
var blobList = container.ListBlobs();
foreach(var blob in blobList)
{
logger.Info($"Blob Name: {blob.Uri}");
}
Run Code Online (Sandbox Code Playgroud)
但是在我的容器中结构是
/
/year/month/day/hour/files
Run Code Online (Sandbox Code Playgroud)
所以现在有
/2017/5/11/14/files
/2017/5/11/17/files
/2017/5/11/22/files
/2017/5/11/23/files
Run Code Online (Sandbox Code Playgroud)
和
/2017/5/12/11/files
Run Code Online (Sandbox Code Playgroud)
其中文件是多个备份文件。
for循环中只有1个项目,因为2017文件夹是根目录。
有没有办法检索所有斑点?
最终目标是删除所有早于保留期的Blob。
我在Service Fabric上运行多个服务.我想添加Application Insight以进行日志记录.我只是想知道是否必须为每个微服务添加一个Application Insight资源,或者只有一个对所有微服务都是通用的.什么是最佳做法?
目标:将日志条目从 NLog 转发到 Azure Application Insights。从:https : //github.com/Microsoft/ApplicationInsights-dotnet-logging
我创建了一个非常基本的控制台应用程序:
TelemetryConfiguration.Active.InstrumentationKey = "my instrumentation key";
Logger logger = LogManager.GetLogger("Example");
logger.Info("Hello World");
Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)
使用以下 app.config:
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
</startup>
<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true">
<extensions>
<add assembly="Microsoft.ApplicationInsights.NLogTarget" />
</extensions>
<targets>
<target type="ApplicationInsightsTarget" name="aiTarget" layout="${longdate} ${level} ${threadid} ${logger} ${message} ${exception:format=ToString}" />
<target name="console" xsi:type="ColoredConsole" layout="${longdate} ${level} ${threadid} ${logger} ${message} ${exception:format=ToString}" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="aiTarget" />
<logger name="*" minlevel="Trace" writeTo="console" />
</rules> …Run Code Online (Sandbox Code Playgroud) 我已经使用 kubernetes 在 Azure 中部署了一个 aspnetcore 项目。
我正在使用 Application Insights,并且我不想从 kubernetes 收到数千条有关成功的活动性和就绪性 (/liveness和/hc) 探测的消息。
是否可以过滤它们?
我已经拥有基于ITelemetryProcessor 的文件管理器。
在我的 Azure 解决方案中,我有 1 个应用程序服务和 2 个功能应用程序记录到 1 个应用程序洞察实例。在特定环境中,我想减少日志记录负载,因此我想摆脱严重性级别 0 的日志。
我目前专注于其中一个功能应用程序,我们将其称为 fa1。我使用 ILogger 添加为 LogDebug 的日志记录语句不会按预期显示在应用程序见解中。但是我可以在应用程序见解中看到以下条目:
我还看到以下条目,但我不知道哪个服务正在生成它们:
主机.json:
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
},
"logLevel": {
"Function": "Warning",
"default": "Warning"
}
}
}
Run Code Online (Sandbox Code Playgroud)
启动.配置():
builder.Services.AddLogging(loggingBuilder =>
{
var key = Environment.GetEnvironmentVariable("APPINSIGHTS_INSTRUMENTATIONKEY");
loggingBuilder.AddApplicationInsights(key);
});
builder.Services.AddSingleton(sp …Run Code Online (Sandbox Code Playgroud) 任何人都可以建议我如何实现添加相关 ID,以便对以下函数的每个 http 请求进行跟踪。
[FunctionName("GetCars")]
public async Task<IActionResult> GetCars([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "api/v1/id/{id}")] HttpRequest req, Guid id)
{
try
{
if (id == Guid.Empty)
{
_logger.LogError("Id is Empty");
}
var cars= _deviceService.GetCars(id);
return new OkObjectResult(cars);
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to Fetch Cars");
}
}
Run Code Online (Sandbox Code Playgroud) c# azure azure-application-insights .net-core azure-functions
我认为使用 args 参数我会在 Azure 应用程序洞察中的 customDimensions 下看到一个新的自定义维度,但它对我不起作用。我找不到有关如何使用此参数的任何好的信息。它的用途是什么?在 App Insights 中哪里可以找到该信息?
我只是传递了一个字符串数组,但在 AI 中找不到这个对象。
//
// Summary:
// Formats and writes an error log message.
//
// Parameters:
// logger:
// The Microsoft.Extensions.Logging.ILogger to write to.
//
// exception:
// The exception to log.
//
// message:
// Format string of the log message in message template format. Example:
// "User {User} logged in from {Address}"
//
// args:
// An object array that contains zero or more objects to format. …Run Code Online (Sandbox Code Playgroud) azure azure-application-insights asp.net-core azure-functions ilogger
我读到的任何地方都应该用它ConfigureAwait(false)来避免死锁和出于性能原因.我们正在使用ConfigureAwait我们的应用程序.但是可能会删除ConfigureAwaits,因为它会导致不同的线程的执行上下文.
不同线程的执行上下文导致(有时)翻译问题.由于当前文化和currentUICulture中的集合文化无法在不同的执行上下文中访问.
我用下面的代码测试了一下.它没有任何性能差异.我知道这不是一个好的测试,因为这个简单的测试没有使用很多线程.
static async Task MyMethodAsync()
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
for (int i = 0; i < 1000; i++)
{
await Task.Delay(10);
await Task.Delay(10).ConfigureAwait(continueOnCapturedContext: false);
}
stopwatch.Stop();
Console.WriteLine("Await: " + stopwatch.Elapsed.ToString());
}
static async Task MyMethodAsyncNoAwait()
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
for (int i = 0; i < 1000; i++)
{
await Task.Delay(10);
await Task.Delay(10);
}
stopwatch.Stop();
Console.WriteLine(stopwatch.Elapsed.ToString());
}
Run Code Online (Sandbox Code Playgroud)
我该如何正确测试?删除所有ConfigureAwaits是一个非常糟糕的主意吗?
在编写 kusto 查询以在我的 azure 仪表板上创建自定义图表时,我希望能够根据用户在仪表板上选择的时间段来计算时间粒度。
例如:最后 4 小时 => 时间粒度 2 分钟,最后 24 小时 => 10 分钟
我尝试了以下方法来计算该期间,因为我们仍然无法访问它(据我在互联网上可以找到的)。
let timeGrain = traces
| summarize min_time = min(timestamp), max_time = max(timestamp)
| extend timeWindow = max_time - min_time // days / hrs/ min / seconds
| project timeWindow
| extend timeGrain = case(timeWindow <= 4h, "2m",
timeWindow <= 12h, "5m",
timeWindow <= 24h, "10m",
"2h")
| project timeGrain;
Run Code Online (Sandbox Code Playgroud)
该查询返回我想要实现的时间粒度,但我无法在其他查询中使用此变量。
traces
...
| summarize percentile(DurationInMs, 50) by bin(timestamp, timeGrain), CommandType
| render …Run Code Online (Sandbox Code Playgroud) 当我们查看默认的 Azure 事件中心时,Event Hub Namespaces我们可以Event Hubs在这些命名空间中进行创建。在Apache Kafka你有Topics.
与an 内的Topican 相同吗?Event HubEvent Hub Namespace
当我们有事件中心(或任何消息服务)的多个使用者时,如何确保没有消息被处理两次,特别是在使用者自动扩展到多个实例的情况下?
我知道我们可以跟踪最后处理的消息,但话又说回来,在检查消息是否已处理和实际处理之间,其他实例已经可以处理它(竞争条件?。
那么,如何以可扩展的方式解决这个问题呢?
[更新] 我知道建议至少拥有与消费者一样多的分区,但是如果单个消费者无法处理定向到它的消息但需要扩展到多个实例,该怎么办?
这似乎表明这始终是必要的,否则您可能会解决不正确的服务 - 因为不能保证服务不会移动等等......
默认的asp.net core服务模板使用
UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
是否有一个原因?什么时候可以不使用ServiceFabricIntegration中间件?
E:我看到这些实际上是一个标志枚举。因此,您可能应该始终使用 UseUniqueServiceUrl https://github.com/Azure/service-fabric-aspnetcore/blob/develop/src/Microsoft.ServiceFabric.AspNetCore/WebHostBuilderServiceFabricExtension.cs
我有这个测试代码。为什么在 using 语句中引发异常时不调用 dispose 方法? 根据文档,它应该被调用。
using System;
using System.IO;
using System.Text;
namespace UsingTest {
class Program {
public class MyClass : IDisposable
{
private bool disposed = false;
public void Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
public void Dispose(bool disposing) {
if (!disposed) {
if (disposing) {
using (var f = new FileStream("log.txt", FileMode.Create)) {
var msg = "MyClass disposed";
f.Write(Encoding.UTF8.GetBytes(msg), 0, Encoding.UTF8.GetByteCount(msg));
}
}
disposed = true;
}
}
~MyClass() {
Dispose(false);
}
}
static void Main(string[] args) …Run Code Online (Sandbox Code Playgroud) azure ×11
c# ×6
asp.net-core ×3
.net ×1
.net-4.6 ×1
.net-core ×1
apache-kafka ×1
async-await ×1
azure-aks ×1
concurrency ×1
ilogger ×1
kql ×1
nlog ×1
performance ×1