nlog

ASP.NET Core使用NLog记录日志

扶醉桌前 提交于 2020-02-05 20:19:50
1、 根目录新建nlog.config配置文件 <?xml version="1.0"?> <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true" internalLogLevel="Warn" internalLogFile="${basedir}\logs\internal-nlog.txt"> <extensions> <add assembly="NLog.Web.AspNetCore"/> </extensions> <targets> <target name="allfile" xsi:type="File" fileName="${basedir}\logs\GDStationaryNetCore\${shortdate}.log" encoding="utf-8" layout="[${longdate}][${machinename}][${level}] ${message} ${exception}" /> </targets> <rules> <!--All logs, including from Microsoft--> <logger name="

Why don't Info level messages get logged when minimum level is Debug?

五迷三道 提交于 2020-02-05 05:24:04
问题 I have the following code in my C# application using Nlog. The messages with 'Debug' get logged, but 'Info' do not. I had assumed that since minLevel is set to 'Debug' in app.config, the 'Info' messages will also get logged, since Debug has higher priority over 'Info'. But they do not get logged. Where am i wrong ? Thanks. if (logger.IsDebugEnabled) logger.Debug(logMessage) else if (logger.IsInfoEnabled)log.Info(logMessage); This is the app.config setting <nlog xmlns="http://www.nlog-project

Are there any alternatives to Common.Logging? [closed]

℡╲_俬逩灬. 提交于 2020-01-23 04:19:27
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . EDIT: Common.Logging 2.1.1 was released on June 9, 2012 and the Github page is fairly active, with the author commenting specifically

Are there any alternatives to Common.Logging? [closed]

ぃ、小莉子 提交于 2020-01-23 04:19:03
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . EDIT: Common.Logging 2.1.1 was released on June 9, 2012 and the Github page is fairly active, with the author commenting specifically

NLog Exception when parsing nlog.config - Target cannot be found: 'EventLog'

﹥>﹥吖頭↗ 提交于 2020-01-23 02:49:12
问题 I'm developing a C# .NET Core 2.2 Web-Api on Visual Studio 2017 . I implement NLog 4.6.1 like described on github. When I start my application using IIS NLog does not write into the Elasticsearch . A error occurs at the line at program.cs var logger = NLog.Web.NLogBuilder.ConfigureNLog("NLog.config").GetCurrentClassLogger(); I find a error message at NLogError.log : 2019-06-12 09:00:49.1606 Error Penter code herearsing configuration from NLog.config failed. Exception: NLog

NLog - Run-Time Parameters for Database Target

筅森魡賤 提交于 2020-01-21 08:22:06
问题 I am attempting to add some customization to my database log target. In my NLog.config I have this: <target name="DatabaseExample1" xsi:type="Database" dbProvider="System.Data.SqlClient" dbDatabase="${event-context:item=dbDatabase}" dbUserName="${event-context:item=dbUserName}" dbPassword="${event-context:item=dbPassword}" dbHost="${event-context:item=dbHost}" commandText="${event-context:item=commandText}"> </target> And in my C# code I have this: protected override void updateBeforeLog

How to create new log file for each application run

≡放荡痞女 提交于 2020-01-21 01:12:32
问题 As the title implies how can I create a new log file for each application run ? I know how to do it for minute/hour/etc. but not for app. run There is what I have for now: target name="Debug" archiveEvery="Hour" archiveFileName="${basedir}/logs/Debug.{#####}.txt" maxArchiveFiles="4" archiveNumbering="Sequence" xsi:type="File" fileName="${basedir}/logs/Debug.txt" layout="${date:format=HH\:mm\:ss} | ${level} | ${message} ${exception} ${exception:format=stacktrace}" But actually I dont need to

C# lock issues when writing to log

心已入冬 提交于 2020-01-17 06:34:14
问题 I have a class that programmatically creates a log using the Nlog framework. I have several processes running and creating their logs at the same time. I added a lock to the constructor of the class, as before the two threads were attempting to create a file at the same time which resulted in some annoying bugs (like only creating one log). This seems to have solved that problem. However now i have the same issue with writing to the log, and using a lock has not helped. Here is the class.

Logging a literal message in NLog and/or Serilog

孤人 提交于 2020-01-16 13:18:19
问题 UPDATE: This turned out to be a discrepancy that exists in Serilog (which I tunnel to), but does not exist in NLog, which treats a single argument as a verbatim string (as one (and specifically, I) might expect) Using NLog, if I want to log something potentially containing embedded double braces: {{ without having them collapsed, what's the most efficient way? e.g.: NLog.LogManager.GetLogger("x").Warn("{{\"aaa}}") emits in my custom serilog-target: {"aaa} And I want: {{"aaa}} Is NLog

Wrapper function for nlog - assigning log level

孤人 提交于 2020-01-16 09:04:03
问题 I want to have a custom log class, which then injects its properties to nlog Logger. The class should initialize nlog target and config , and then others can use it without the need to know those details. public interface ILogger { void Log(LogEntry entry); } public enum LoggingEventType { Debug, Information, Warning, Error, Fatal}; public class LogEntry { public readonly LoggingEventType Level; public readonly string Message; public readonly Exception Ex; public LogEntry(LoggingEventType