c# - how to use both the log writer and app insights within azure function?
问题描述
I'd like to send trace and other events to both the ILogger
as well as application insights.
I know that I can simply do this:
[FunctionName ("OnSomethingHttpTriggered")]
public static async System.Threading.Tasks.Task RunAsync ([QueueTrigger ("myq", Connection = "StorageAccountConnection")] string payload, ILogger log) {
var telemetry = new TelemetryClient {
InstrumentationKey = Environment.GetEnvironmentVariable ("APPINSIGHTS_INSTRUMENTATIONKEY")
};
log.LogInformation ($"C# Queue trigger function processed: {payload}");
telemetry.TrackEvent ($"C# Queue trigger function processed: {payload}");
var isPayloadValidSchema = SchemaValidator.IsValid (payload);
if (!isPayloadValidSchema) {
log.LogError ($"This visit is not valid {payload}");
telemetry.TrackEvent ($"This visit is not valid {payload}");
return;
}
}
But as you can see I would need to double my code each time for ILogger
and TelemetryClient
.
How do I avoid this repetition?
解决方案
推荐阅读
- api - 谷歌云上托管的 api 文件路径问题
- python - 从头开始实现 tf-idf 以返回前 n 个特征 wrt 前 n 个 IDF 值
- java - 如何返回数组而不是任务?
- python-3.x - 安装 scikit-learn 时卡在“正在安装构建依赖项...”
- azure-data-factory-2 - 数据工厂不喜欢美国东部标准时间
- python - proxy_trusted_ips 的 Django ipware 环境变量
- java - 意外行为 java 优先级队列。对象添加了一次但轮询了两次。怎么可能?
- python - 我在 python turtle 中画枫叶时遇到问题
- c# - 为什么我的透视变换不起作用
- python-3.x - 将参数从文本插入文件