标签:val rod nio static except current sse open following
If you have trouble getting NLog to work properly you may want to enable internal logging, which can help identify where the problem is. Internal log output can be sent to a file, console window or both.
When you configure NLog using Configuration File, you can enable internal logging by setting the following attribute on the <nlog>
element:
internalLogLevel="Off|Trace|Debug|Info|Warn|Error|Fatal"
– determines internal log level. The higher the level, the less verbose the internal log output.internalLogFile="file.txt"
- adding internalLogFile cause NLog to write its internal debugging messages to the specified file. This includes any exceptions that may be thrown during logging.
%appdata%
${currentdir}
, ${basedir}
, ${tempdir}
${processdir}
internalLogToConsole="false|true"
– sends internal logging messages to the console.internalLogToConsoleError="false|true"
– sends internal logging messages to the console error output (stderr).internalLogToTrace="false|true"
– sends internal logging messages to System.Diagnostics.Trace
(introduced in NLog 4.3)internalLogIncludeTimestamp="false|true"
- indicates whether timestamps should be included in the internal log output (NLog 4.3+)Here is an example of a configuration file which enables internal logging to a file:
<nlog internalLogFile="c:\log.txt" internalLogLevel="Trace">
<targets>
<!-- target configuration here -->
</targets>
<rules>
<!-- log routing rules -->
</rules>
</nlog>
There are environment variables which control internal logging. You can set those variables before running your program to enable internal logging:
System.Diagnostics.Trace
(introduced in NLog 4.3)Internal logging can be configured through code by setting the following properties on InternalLogger class:
System.Diagnostics.Trace
(introduced in NLog 4.3)TextWriter
object to use for loggingusing NLog;
using NLog.Common;
class Program
{
static void Main()
{
// enable internal logging to the console
InternalLogger.LogToConsole = true;
// enable internal logging to a file
InternalLogger.LogFile = "c:\\log.txt";
// enable internal logging to a custom TextWriter
InternalLogger.LogWriter = new StringWriter(); //e.g. TextWriter writer = File.CreateText("C:\\perl.txt")
// set internal log level
InternalLogger.LogLevel = LogLevel.Trace;
}
}
Maybe NLog can‘t find your nlog.config, see Logging-troubleshooting
2020-07-06 11:44:20.7883 Warn Failed to create file appender: log\rule\Rule_Info_20200706.log Exception: System.UnauthorizedAccessException: Access to the path ‘log\rule\Rule_Info_20200706.log‘ is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileSystemRights rights, FileShare share, Int32 bufferSize, FileOptions options)
at NLog.Internal.FileAppenders.WindowsMultiProcessFileAppender.CreateAppendOnlyFile(String fileName)
at NLog.Internal.FileAppenders.WindowsMultiProcessFileAppender..ctor(String fileName, ICreateFileParameters parameters)
at NLog.Internal.FileAppenders.WindowsMultiProcessFileAppender.Factory.NLog.Internal.FileAppenders.IFileAppenderFactory.Open(String fileName, ICreateFileParameters parameters)
at NLog.Internal.FileAppenders.FileAppenderCache.CreateAppender(String fileName, Int32 freeSpot)
标签:val rod nio static except current sse open following
原文地址:https://www.cnblogs.com/chucklu/p/13253880.html