首页 > 解决方案 > C#-在哪里使用带有 azure 函数应用程序的 log4net 设置?

问题描述

我正在使用 azure 函数,为了将异常详细信息记录到 Azure 函数中的应用程序洞察力,我使用 TelemetryClient() 对象以及如下所示的检测密钥来记录消息

示例

 var telemetryClient = new TelemetryClient();
 telemetryClient.InstrumentationKey = ConfigurationSettings.AppSettings["APPINSIGHTS_INSTRUMENTATIONKEY"];
 appInsights.TrackEvent(message);

所以,现在我想使用 Log4Net 通过 azure 函数将消息记录到应用程序洞察力。

在这里找到一些信息 Log4Net with Application Insights

为了使用具有适用洞察力的 log4net 日志,在 azure 函数中进行以下设置的位置在哪里?由于 azure function app 没有 web.config 文件。

我可以添加自定义配置文件并在下面设置并使用它吗?

  <configuration>
  <configSections>
       <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  </configSections>
  <log4net>
    <root>
      <level value="ALL"/>
      <appender-ref ref="aiAppender"/>
    </root>
    <appender name="aiAppender" type="Microsoft.ApplicationInsights.Log4NetAppender.ApplicationInsightsAppender, Microsoft.ApplicationInsights.Log4NetAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%message%newline"/>
      </layout>
    </appender>
  </log4net>
<configuration>

标签: azure-application-insightslog4net-configurationlog4net-appenderazure-application-settings

解决方案


推荐阅读