CSoft.LoggerNLog
5.0.4
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package CSoft.LoggerNLog --version 5.0.4
NuGet\Install-Package CSoft.LoggerNLog -Version 5.0.4
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="CSoft.LoggerNLog" Version="5.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CSoft.LoggerNLog --version 5.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CSoft.LoggerNLog, 5.0.4"
#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 CSoft.LoggerNLog as a Cake Addin #addin nuget:?package=CSoft.LoggerNLog&version=5.0.4 // Install CSoft.LoggerNLog as a Cake Tool #tool nuget:?package=CSoft.LoggerNLog&version=5.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Log
日志存储
第一步
一般情况,可加参数表示指定文件名
Logs.LogFactory = new NLogFactory();
Android下自动读取Assets下的配置
Logs.LogFactory = new NLogFactory("assets/NLog.config");
第二步
Android下的配置文件,其他的无非给下路径,Android下路径不熟,给个例子,详见文章尾部摘抄
<?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"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
<variable name="myvar" value="myvalue"/>
<variable name="logDir" value="${specialfolder:folder=MyDocuments}/Logs/"/>
<targets async="true">
<target xsi:type="File" name="error" fileName="${logDir}/Error/${shortdate}.log" layout="${level:upperCase=true} ${longdate} ${logger} ${callsite:skipFrames=2} ${message} ${onexception:${newline} ${exception:format=toString,Data} ${newline} ${stacktrace} ${newline}"/>
<target xsi:type="File" name="info" fileName="${logDir}/Info/${shortdate}.log" layout="${level:upperCase=true} ${longdate} ${logger} ${callsite:skipFrames=2} ${message}"/>
<target xsi:type="File" name="warn" fileName="${logDir}/Warn/${shortdate}.log" layout=" ${level:upperCase=true} ${longdate} ${logger} ${callsite:skipFrames=2} ${message} ${onexception:${newline} ${exception:format=toString,Data} ${newline} ${stacktrace} ${newline}"/>
<target xsi:type="File" name="trace" fileName="${logDir}/Trace/${shortdate}.log" layout=" ${longdate} ${message}"/>
<target xsi:type="File" name="debug" fileName="${logDir}/Debug/${shortdate}.log" layout=" ${longdate} ${message}"/>
</targets>
<rules>
<logger name="*" minlevel="Error" maxlevel="Error" writeTo="error"/>
<logger name="*" minlevel="Info" maxlevel="Info" writeTo="info"/>
<logger name="*" minlevel="Warn" maxlevel="Warn" writeTo="warn"/>
<logger name="*" minlevel="Trace" maxlevel="Trace" writeTo="trace"/>
<logger name="*" minlevel="Debug" maxlevel="Debug" writeTo="debug"/>
</rules>
</nlog>
第三步
在使用到的类中加入
//Main是你需要调用的类
private static readonly ILogger _logger = Logs.LogFactory.GetLogger<Main>();
第四步
可在需要位置输出日志,比如:
_logger.Info("hello");
_logger.Error(e.Exception);
*附NLog文件路径规则
System special folder path (includes My Documents, My Music, Program Files, Desktop, and more).
Platforms Supported: Limited (Not supported on NetStandard1.3+1.5)
See also ${processdir} , ${basedir} , ${currentdir} , ${tempdir}
Configuration Syntax
${specialfolder:dir=String:file=String:folder=Enum}
Parameters
Advanced Options
- dir - Name of the directory to be Path.Combine()'d with the directory name.
- file - Name of the file to be Path.Combine()'d with the directory name.
Rendering Options
folder - System special folder to use. Full list of options is available at MSDN. The most common ones are:
- ApplicationData - Roaming application data for current user
- Windows Path =
C:\Users\%USERNAME%\AppData\Roaming
- Xamarin Mono =
$HOME/.config
(or $XDG_CONFIG_HOME if set) - Xamarin iOS =
/data/Containers/Data/Application/@GENERATED_NAME@/Documents/.config
- Xamarin Android =
/data/data/@PACKAGE_NAME@/files/.config
- Windows Path =
- LocalApplicationData - Non roaming application data for current user
- Windows Path =
C:\Users\%USERNAME%\AppData\Local
- Xamarin Mono =
$HOME/.local/share
(or $XDG_DATA_HOME if set) - Xamarin iOS =
/data/Containers/Data/Application/@GENERATED_NAME@/Documents
- Xamarin Android =
/data/data/@PACKAGE_NAME@/files/.local/share
- Windows Path =
- CommonApplicationData - Application data for all users (Good when running as Windows Service)
- Windows Path =
C:\ProgramData
- Xamarin Mono =
/usr/share
- Xamarin iOS =
/usr/share
- Xamarin Android =
/usr/share
- Windows Path =
- MyDocuments - My Documents
- Windows Path =
C:\Users\%USERNAME%\Documents
- Xamarin Mono =
$HOME
- Xamarin iOS =
/data/Containers/Data/Application/@GENERATED_NAME@/Documents
- Xamarin Android =
/data/data/@PACKAGE_NAME@/files
- Windows Path =
- Desktop - My Desktop
- Windows Path =
C:\Users\%USERNAME%\Desktop
- Xamarin Mono =
$HOME/Desktop
(or $XDG_DESKTOP_DIR if set) - Xamarin iOS =
/data/Containers/Data/Application/@GENERATED_NAME@/Documents/Desktop
- Xamarin Android =
/data/data/@PACKAGE_NAME@/files/Desktop
- Windows Path =
- UserProfile
- Windows Path =
C:\Users\%USERNAME%
- Xamarin Mono =
$HOME
- Xamarin iOS =
/data/Containers/Data/Application/@GENERATED_NAME@
- Xamarin Android =
/data/data/@PACKAGE_NAME@/files
- Windows Path =
- Templates
- Windows Path =
C:\Users\%USERNAME%\AppData\Roaming\Microsoft\Windows\Templates
- Xamarin Mono =
$HOME/Templates
(or $XDG_TEMPLATES_DIR if set) - Xamarin iOS =
/data/Containers/Data/Application/@GENERATED_NAME@/Documents/Templates
- Xamarin Android =
/data/data/@PACKAGE_NAME@/files/Templates
- Windows Path =
- CommonTemplates
- Windows Path =
C:\ProgramData\Microsoft\Windows\Templates
- Xamarin Mono =
/usr/share/templates
- Xamarin iOS =
/usr/share/templates
- Xamarin Android =
/usr/share/templates
- Windows Path =
- Resources
- Windows Path =
C:\WINDOWS\resources
- Xamarin iOS =
/Library
- Windows Path =
- AdminTools
- CommonAdminTools
- CommonDesktopDirectory
- CommonDocuments
- CommonMusic
- CommonPictures
- CommonProgramFiles
- CommonProgramFilesX86
- CommonPrograms
- CommonStartMenu
- CommonStartup
- CommonVideos
- Cookies
- DesktopDirectory (Same as Desktop)
- Favorites
- Fonts
- History
- LocalizedResources
- MyComputer
- MyMusic
- MyPictures
- MyVideos
- NetworkShortcuts
- Personal (Same as MyDocuments)
- PrinterShortcuts
- ProgramFiles
- ProgramFilesX86
- Programs
- Recent
- SendTo
- StartMenu
- Startup
- System
- SystemX86
- Windows
- ApplicationData - Roaming application data for current user
Product | Versions 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 | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | 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.
-
.NETStandard 2.1
- CSoft.LogInterface (>= 5.0.2)
- Newtonsoft.Json (>= 13.0.1)
- NLog (>= 4.7.9)
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 | |
---|---|---|---|
8.0.2 | 122 | 7/10/2024 | |
8.0.1 | 236 | 12/29/2023 | |
8.0.0 | 198 | 11/15/2023 | |
7.0.4 | 176 | 8/22/2023 | |
7.0.3 | 199 | 6/13/2023 | |
7.0.2 | 220 | 4/21/2023 | |
7.0.1 | 336 | 2/2/2023 | |
7.0.0 | 438 | 11/9/2022 | |
6.0.5 | 498 | 9/23/2022 | |
6.0.4 | 521 | 8/11/2022 | |
6.0.3 | 501 | 6/1/2022 | |
6.0.2 | 495 | 5/12/2022 | |
6.0.1 | 522 | 3/15/2022 | |
5.0.5 | 638 | 8/18/2021 | |
5.0.4 | 467 | 4/29/2021 | |
5.0.3 | 496 | 3/11/2021 | |
5.0.2 | 531 | 1/22/2021 | |
5.0.1 | 510 | 1/21/2021 | |
5.0.0 | 507 | 1/20/2021 |
使用NLog输出日志