nlog

NLog is not writing to database table

三世轮回 提交于 2019-12-08 00:40:45
问题 This is my NLog Config file. <?xml version="1.0" ?> <nlog autoReload="true" throwExceptions="true" internalLogLevel="Debug" internalLogToConsole="true" internalLogFile="c:\\temp\\nlog.txt" > <targets> <!--Useful for debugging--> <target name="consolelog" type="ColoredConsole" layout="${date:format=HH\:mm\:ss}|${level}|${stacktrace}|${message}" /> <target name="filelog" type="File" fileName="c:\\temp\\nlog1.txt" layout="${date}: ${message}" /> <target name="eventlog" type="EventLog" source="My

Creating folder for log files for NLog with InnoSetup

戏子无情 提交于 2019-12-07 23:47:53
问题 I'm having an issue where I need my users to be able to run my application without administrator rights, but at the same time, I need NLog to be able to create it's log files, which it needs administrator rights to create them in the same folder the application is installed in. I'm trying to create a directory under the application directory, named Logs , and give everyone-modify permissions with inno setup. I'm going to set up my NLog config to write to this new Logs folder instead of the

Prevent expensive log call if log level is below threshold

廉价感情. 提交于 2019-12-07 17:49:31
问题 If I do a NLog.Trace(): logger.Trace("Json: {0}", Newtonsoft.Json.JsonConvert.DeserializeObject(myObject)); And my minlevel is on Error: <logger name="*" minlevel="Error" writeTo="mail" enabled="false" /> Will my object be deserialized for nothing? Yes, of course yes. But how can I avoid this? 回答1: if(logger.IsTraceEnabled) logger.Trace("Json: {0}", Newtonsoft.Json.JsonConvert.SerializeObject(myObject)); See IsTraceEnabled. This is good practice for logging calls where the call itself can be

Logging exception in ASP.NET Core with NLog

丶灬走出姿态 提交于 2019-12-07 17:09:10
问题 I'm currently trying to log the exception message, etc using NLog, no luck so far, and I can't imagine why To setup NLog I used this guide: https://github.com/NLog/NLog.Web/wiki/Getting-started-with-ASP.NET-Core-(project.json) I've setup this on the asp.net core, and tried the logging on my bussiness project Bussiness using Microsoft.Extensions.Logging; public class FileService { private readonly ILogger<FileService> _logger; public Task<DataResult<ICollection<BlankDTO>>> Test(Guid appId,

Nlog Async and Log Sequence

人走茶凉 提交于 2019-12-07 12:14:46
问题 In my nlog configuration, I've set <targets async="true"> with the understanding that all logging now happens asynchronously to my application workflow. (and I have noticed a performance improvement, especially on the Email target). This has me thinking about log sequence though. I understand that with async, one has no guarantee of the order in which the OS will execute the async work. So if, in my web app, multiple requests come in to the same method, each logging their occurrence to NLog,

Logging exception properties

为君一笑 提交于 2019-12-07 09:46:21
问题 Is it possible to log properties of exception with NLog? For example SocketException has properties such as ErrorCode, HResult, NativeErrorCode, etc that are specific to only this type of exceptions. It is possible to log them without explicitly logging (i.e without using Log(e.ErrorCode) ) them and using just ErrorException from the code? The default Exception layout renderer just calls ToString on the exception. 回答1: I don't know if it's a very good idea, but you can write your own

NLog - Only log while debugging

泪湿孤枕 提交于 2019-12-07 09:18:32
问题 Take this simple NLog example configuration: <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="file.txt" /> </targets> <rules> <logger name="*" minlevel="Debug" writeTo="logfile" /> </rules> </nlog> How can this be set up to only log while debugging, and not when run in production? EDIT: To make things a bit more challenging: My NLog configuration files are centralized,

Is there a way to set the minlevel of a NLog logger via a variable?

丶灬走出姿态 提交于 2019-12-07 04:12:23
Using NLog v4.4.12, I have this in my App.config <nlog> <include file="..\Common\Logs\Variables.xml" /> <rules> <logger name="*" minlevel="${logLevel}" writeTo="LogFile, Wcf"/> </rules> </nlog> And here is my Variables.xml file content <?xml version="1.0" encoding="utf-8"?> <nlog autoReload="true"> <variable name="logLevel" value="Fatal" /> </nlog> But I get an Exception when launching my app Unknown log level: ${logLevel} Am I doing something wrong or is it just impossible? The goal of this is to eventually have an xml file per project that need to log things so each project can have his own

How to tell NLog to log exceptions?

流过昼夜 提交于 2019-12-07 01:40:55
问题 Target: <targets> <target name="file" xsi:type="File" layout="${longdate} ${level} ${message} ${exception}" fileName="${basedir}/log.txt" archiveAboveSize="10485760" /> </targets> When I call Logger.Error("some message", e) , where e is some exception object, it only logs the message, not the exception information. I need it to output exception message and stack trace. Any ideas what I am doing wrong? 回答1: Try to use ${exception:innerFormat=Message,StackTrace} . Here is the documentation. 回答2

How to configure NLog to get IP address .NET Core

眉间皱痕 提交于 2019-12-07 00:37:58
问题 I develop .net core app and use NLog as logging framework. How can I setup NLog layout to get remote IP address? Unfortunately, ${aspnet-request.serverVariable=remote_addr} isn't supported by NLog.Web.AspNetCore . May be I can get access to httpContext.Connection.RemoteIpAddress somehow. 回答1: This is supported since NLog.Web.AspNetCore 4.4.0. Install the package NLog.Web.AspNetCore Set in your config <!-- enable asp.net core layout renderers --> <extensions> <add assembly="NLog.Web.AspNetCore