项目作者: NLog

项目描述 :
NLog target for Microsoft Visual Studio App Center with Azure
高级语言: C#
项目地址: git://github.com/NLog/NLog.AzureAppCenter.git
创建时间: 2019-08-17T14:01:15Z
项目社区:https://github.com/NLog/NLog.AzureAppCenter

开源协议:BSD 3-Clause "New" or "Revised" License

下载


NLog.Targets.AppCenter

NLog Target for Microsoft Visual Studio App Center with Azure

Version
AppVeyor

⚠️ Microsoft AppCenter will be retired - https://learn.microsoft.com/appcenter/retirement

How to setup NLog in MAUI

1) Install the NLog packages

  • Install-Package NLog.Targets.AppCenter
  • Install-Package NLog.Extensions.Logging

    or in your csproj:

    1. <PackageReference Include="NLog.Targets.AppCenter" Version="5.*" ></PackageReference>
    2. <PackageReference Include="NLog.Extensions.Logging" Version="5.*" ></PackageReference>

2) Add NLog to the MauiApp

Update MauiProgram.cs to include NLog as Logging Provider:

  1. var builder = MauiApp.CreateBuilder();
  2. // Add NLog for Logging
  3. builder.Logging.ClearProviders();
  4. builder.Logging.AddNLog();

If getting compiler errors with unknown methods, then update using-section:

  1. using Microsoft.Extensions.Logging;
  2. using NLog;
  3. using NLog.Extensions.Logging;

3) Load NLog configuration for logging

Add the NLog.config-file into the Application-project as assembly-resource (Build Action = embedded resource), and load like this:

  1. NLog.LogManager.Setup().RegisterAppCenter()
  2. .LoadConfigurationFromAssemblyResource(typeof(App).Assembly);

Alternative setup NLog configuration using fluent-API:

  1. var logger = NLog.LogManager.Setup().RegisterAppCenter()
  2. .LoadConfiguration(c => c.ForLogger().FilterMinLevel(NLog.LogLevel.Debug).WriteToAppCenter())
  3. .GetCurrentClassLogger();

Configuration options for AppCenter NLog Target

  • AppSecret - Appsecret for starting AppCenter if needed (optional)
  • UserId - Application UserId to register in AppCenter (optional)
  • LogUrl - Base URL (scheme + authority + port only) to the AppCenter-backend (optional)
  • CountryCode - Two-letter ISO country code to send to the AppCenter-backend (optional)
  • DataResidencyRegion - Country Code or other identifier of data residency region (optional)
  • ReportExceptionAsCrash - Report all exceptions as crashes to AppCenter (default=false)
  • IncludeEventProperties - Include LogEvent properties in AppCenter properties (default=true)
  • IncludeScopeProperties - Include MappedDiagnosticsLogicalContext (MLDC) that can be provided with MEL BeginScope (default=false)

Example NLog.config file

  1. <nlog throwConfigExceptions="true">
  2. <extensions>
  3. <add assembly="NLog.Targets.AppCenter"></add>
  4. </extensions>
  5. <targets>
  6. <target name="appcenter" type="appcenter" layout="${message}" reportExceptionAsCrash="true">
  7. <contextproperty name="logger" layout="${logger}" ></contextproperty>
  8. <contextproperty name="loglevel" layout="${level}" ></contextproperty>
  9. <contextproperty name="threadid" layout="${threadid}" ></contextproperty>
  10. </target>
  11. </targets>
  12. <rules>
  13. <logger name="*" minLevel="Info" writeTo="appcenter" ></logger>
  14. </rules>
  15. </nlog>