NLog.NetworkTarget 1.0.1.6

dotnet add package NLog.NetworkTarget --version 1.0.1.6
                    
NuGet\Install-Package NLog.NetworkTarget -Version 1.0.1.6
                    
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="NLog.NetworkTarget" Version="1.0.1.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NLog.NetworkTarget" Version="1.0.1.6" />
                    
Directory.Packages.props
<PackageReference Include="NLog.NetworkTarget" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NLog.NetworkTarget --version 1.0.1.6
                    
#r "nuget: NLog.NetworkTarget, 1.0.1.6"
                    
#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.
#:package NLog.NetworkTarget@1.0.1.6
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NLog.NetworkTarget&version=1.0.1.6
                    
Install as a Cake Addin
#tool nuget:?package=NLog.NetworkTarget&version=1.0.1.6
                    
Install as a Cake Tool

NLog.NetworkTarget

编辑 nlog.config


	<extensions>
		<add assembly="NLog.NetworkTarget"/>
	</extensions>
	<targets async="true">
		<target xsi:type="JsonNetwork" name="server" address="http post 地址" layout="${jsonnetwork}" />
	</targets>
	<rules>
		<logger name="*" minlevel="Info" writeTo="server"/>
		<logger name="allfilelog" minlevel="Info" writeTo="allfilelog"/>
	</rules>

完整文档


<?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="/var/log/parking/internal-nlog.txt">

	
	<extensions>
		<add assembly="NLog.Web.AspNetCore"/>
		<add assembly="NLog.NetworkTarget"/>
	</extensions>
	<variable name="logdir" value="/var/log/parking/"/>
	
	<targets async="true">
		
		<target xsi:type="File" name="sql" fileName="${logdir}/sql/${shortdate}.log"
				layout="${longdate}|${uppercase:${level}}${newline}${message}${newline}" />

		<target xsi:type="File" name="hangfire" fileName="${logdir}/hangfire/${shortdate}.log"
				layout="${longdate}|${uppercase:${level}}${newline}${message}${newline}" />

		<target xsi:type="File" name="tcp" fileName="${logdir}/tcp/${shortdate}.log"
				layout="${longdate}|${uppercase:${level}}${newline}${message}${newline}" />

		<target xsi:type="File" name="memoryinfo" fileName="${logdir}/memoryinfo/${shortdate}.log"
				layout="${longdate}|${uppercase:${level}}${newline}${message}${newline}" />

		<target xsi:type="File" name="platetcp" fileName="${logdir}/${shortdate}_tcp.log"
				layout="${longdate}|${uppercase:${level}}${newline}${message}${newline}" />

		<target xsi:type="JsonNetwork" name="server" address="http://localhost:9000/api/httptest/upload" layout="${jsonnetwork}" />

		<target xsi:type="Null" name="blackhole" />
	</targets>

	
	<rules>
		
		<logger name="Microsoft.*" minlevel="Trace" writeTo="blackhole" final="true" />
		<logger name="Hangfire.*" minlevel="Trace" writeTo="blackhole" final="true" />
		<logger name="Sync" minlevel="Info" writeTo="sql" final="true" />
		<logger name="Tcp" minlevel="Info" writeTo="tcp" final="true" />
		<logger name="PlateTCP.*" minlevel="Info" writeTo="platetcp" final="true" />
		<logger name="Memoryinfo" minlevel="Info" writeTo="memoryinfo" final="true" />
		<logger name="*" minlevel="Info" writeTo="server"/>
		<logger name="allfilelog" minlevel="Info" writeTo="allfilelog"/> 
	</rules>
</nlog>

Program


	LoggerFormat.ArgsName = new string[] { "RobotId", "Plate" };

注意:此上传内容定义标记需在 日志上传前定义

写日志


	_logger.LogInformation($"{LoggerFormat.Write("0575aa74-f4d7-49f7-a052-17b3cf5bebb1", "川Z00000")}这里开始写入日志文件的内容");

write 写入参数顺序 按 LoggerFormat.ArgsName 定义顺序传入

日志写入后效果

日志文件效果

2024-08-01 21:03:15.9674|TestController|INFO|gc(TestController.cs:90)
这里开始写入日志文件的内容 

日志服务器接受到数据效果


{"Time":ISODate("2024-08-01T21:30:04.806Z"),"Level":"Info","RobotId":"0575aa74-f4d7-49f7-a052-17b3cf5bebb1","Plate":"川Z00000","Message":"这里开始写入日志文件的内容"}

按业务写入不同文件

Program


	AspNetExtensions.UseNLog().ConfigureNLog()

	var list = new List<FilterOption> {
		new FilterOption{ Targetname="server1", FileName="1" , MinLevel="Debug" }, //指定级别 否则 默认 Info
		new FilterOption{ Targetname="server2", FileName="2" },
	};
	NLogger.Configure(list);

注意:此定义 必须在 app.build 前 否则 nlog 不会加载生效

写日志


	_logger.LogInformation($"{LoggerFormat.WriteTag("server1","0575aa74-f4d7-49f7-a052-17b3cf5bebb1", "川Z00000")}这里开始写入日志文件的内容");

生成日志文件


	2024-08-07-1.log 2024-08-07-2.log

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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 is compatible. 
.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.1.6 147 3/13/2026
1.0.1.5 440 8/8/2024
1.0.1.4 189 8/8/2024
1.0.1.3 182 8/7/2024
1.0.1.2 186 8/7/2024
1.0.1.1 155 8/6/2024
1.0.0.2 160 8/1/2024
1.0.0.1 147 8/1/2024