MasterServer.Lib.Logging.NLog 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package MasterServer.Lib.Logging.NLog --version 1.0.0
                    
NuGet\Install-Package MasterServer.Lib.Logging.NLog -Version 1.0.0
                    
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="MasterServer.Lib.Logging.NLog" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MasterServer.Lib.Logging.NLog" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="MasterServer.Lib.Logging.NLog" />
                    
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 MasterServer.Lib.Logging.NLog --version 1.0.0
                    
#r "nuget: MasterServer.Lib.Logging.NLog, 1.0.0"
                    
#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 MasterServer.Lib.Logging.NLog@1.0.0
                    
#: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=MasterServer.Lib.Logging.NLog&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=MasterServer.Lib.Logging.NLog&version=1.0.0
                    
Install as a Cake Tool

Automation.Lib.Logging.NLog

基于NLog的日志实现库,提供配置文件和代码配置支持。

特性

  • 基于NLog 6.x的强大日志功能
  • 支持配置文件(nlog.config)
  • 支持代码配置(默认控制台+文件)
  • 集成Microsoft.Extensions.Logging
  • 支持多种日志目标(文件、控制台、数据库等)
  • 支持日志级别过滤
  • 支持异步日志记录

使用方式

1. 在依赖注入中使用

using Microsoft.Extensions.DependencyInjection;
using Automation.Lib.Logging;

var services = new ServiceCollection();

// 添加NLog日志支持,使用配置文件
services.AddLoggingWithNLog("nlog.config");

// 或使用默认配置
services.AddLoggingWithNLog();

var serviceProvider = services.BuildServiceProvider();

// 使用日志
var logger = serviceProvider.GetRequiredService<ILogger<Program>>();
logger.Info("应用程序启动");

2. 在依赖注入中使用(配合MasterServer.Lib.Ioc项目,推荐)

using Microsoft.Extensions.DependencyInjection;
using Automation.Lib.Logging;
using Automation.Lib.Ioc;

var services = new ServiceCollection();
services.AddLoggingWithNLog();

// 注册服务
ServiceInstaller.RegisterToIocFromAssembly(services, "Test");

var logger = ServiceInstaller.Resolve<ILogger<PlcService>>();
logger.Info("测试3");

3. 静态初始化(无DI,推荐)

using Automation.Lib.Logging;

// 初始化NLog。三个参数都有默认值,可以为空
LoggingExtensions.InitializeNLog("nlog.config", "logs", NLog.LogLevel.Info);

// 使用静态日志
LoggerExtensions.Info("这是一条信息日志");
LoggerExtensions.Error("这是一条错误日志");

3. NLog配置文件示例 (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">

  <targets>
    <target name="logfile" xsi:type="File" fileName="logs/log-${shortdate}.log"
            layout="${longdate}|${level:uppercase=true}|${logger}|${message}" />
    <target name="logconsole" xsi:type="Console"
            layout="${longdate}|${level:uppercase=true}|${logger}|${message}" />
  </targets>

  <rules>
    <logger name="*" minlevel="Info" writeTo="logconsole" />
    <logger name="*" minlevel="Debug" writeTo="logfile" />
  </rules>
</nlog>

安装

通过NuGet安装:

Install-Package Automation.Lib.Logging.NLog

依赖

  • NLog
  • NLog.Extensions.Logging
  • Microsoft.Extensions.Logging
  • Automation.Lib.Logging</content>
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.  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 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
2.0.0 98 4/23/2026
1.0.2 175 12/26/2025
1.0.1 194 12/25/2025
1.0.0 197 12/25/2025

日志抽象包