Microliu.Core.Logger 1.0.2

dotnet add package Microliu.Core.Logger --version 1.0.2
NuGet\Install-Package Microliu.Core.Logger -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Microliu.Core.Logger" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Microliu.Core.Logger --version 1.0.2
#r "nuget: Microliu.Core.Logger, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Microliu.Core.Logger as a Cake Addin
#addin nuget:?package=Microliu.Core.Logger&version=1.0.2

// Install Microliu.Core.Logger as a Cake Tool
#tool nuget:?package=Microliu.Core.Logger&version=1.0.2

新建Asp.net core 2.2+项目

安装NuGet

Exceptionless 4.3.2027
Exceptionless.AspNetCore 4.3.2027
Exceptionless.NLog 4.3.2027
NLog 4.6.8
NLog.Web.AspNetCore 4.9.0

新增配置文件nlog.config

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
	  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	  autoReload="true"
	  internalLogLevel="Info"
	  internalLogFile="c:\temp\internal-nlog.txt">

  
  <extensions>
	<add assembly="NLog.Web.AspNetCore"/>
	<add assembly="Exceptionless.NLog"/>
  </extensions>

  
  <targets>
	
	<target xsi:type="File" name="allfile" fileName="${basedir}/logs/${shortdate}(all).log"
			layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}" />

	
	<target xsi:type="File" name="ownFile-web" fileName="${basedir}/logs/${shortdate}(own).log"
			layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />

	<target name="logconsole" xsi:type="Console" />


	<target xsi:type="Exceptionless" name="exceptionless" apiKey="ov7WSaIWUYaeIRnenHCrxkmBt9OSPZHAFBvyHopY" serverUrl="http://10.0.0.101:11012">
       		<field name="host" layout="${machinename}" />
       		<field name="identity" layout="${identity}" />
       		<field name="windows-identity" layout="${windows-identity:userName=True:domain=False}" />
       		<field name="process" layout="${processname}" />
     
	</target>
  </targets>

  
  <rules>
	
	<logger name="*" minlevel="Trace" writeTo="allfile" />

	
	<logger name="Microsoft.*" maxlevel="Info" final="true" />
	
	<logger name="*" minlevel="Trace" writeTo="ownFile-web" />
	<logger name="*" minlevel="Trace" writeTo="logconsole" />
	<logger name="*" minlevel="Trace" writeTo="exceptionless" />
  </rules>
</nlog>

application.*.json { "Logging": { "IncludeScopes": true, "LogLevel": { "Default": "Information", //Trace,Information,Warning,Error,Debug "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } } }

写入代码到Program.cs

using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NLog.Web;
using System;

namespace Microliu.Core.LoggerTest
{
	public class Program
	{
		public static void Main(string[] args)
		{
			var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
			try
			{
				logger.Debug("[启动程序] [Main]");
				CreateHostBuilder(args).Build().Run();
			}
			catch (Exception exception)
			{
				//NLog: catch setup errors
				logger.Error(exception, "[程序执行中异常]");
				throw;
			}
			finally
			{
				// Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux)
				NLog.LogManager.Shutdown();
				logger.Info("[程序停止运行]");
			}
		}

		public static IHostBuilder CreateHostBuilder(string[] args) =>
			Host.CreateDefaultBuilder(args)
				.ConfigureWebHostDefaults(webBuilder =>
				{
					webBuilder.UseStartup<Startup>();
				}).ConfigureLogging(logging =>
				{
					logging.ClearProviders();
					logging.SetMinimumLevel(LogLevel.Trace);
				})
				.UseNLog();// NLog: Setup NLog for Dependency injection
	}
}

修改配置文件

连接Exceptionless 修改nlog.config中的 apiKey和serverUrl即可 <target xsi:type="Exceptionless" name="exceptionless" apiKey="apiKey" serverUrl="http://10.0.0.101:11012">

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 540 12/12/2019
1.0.1 436 11/11/2019
1.0.0 533 11/11/2019