nlog

NLog - delete logs older than X days

£可爱£侵袭症+ 提交于 2019-12-06 21:40:01
问题 How I can delete files with logs older than X days. It's simple, but I have in one folder logs only from one day. My NLog.config looks like: <?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" autoReload="true"> <extensions> <add assembly="NLog.Extended" /> </extensions> <variable name="LogHome" value="PATH"/> <variable name="DailyDir" value="${LogHome}${date:format=yyyy}/${date:format=MM}/$

NLog not working in release mode

試著忘記壹切 提交于 2019-12-06 18:02:48
问题 I am using NLog to log the exceptions in my asp.net mvc (C#) application. NLog is not working in release mode. The same is working when running in debug mode. What may be the problem? Is there any fix for this? 回答1: I was having the same problem as you: ASP.NET MVC 3 .NET 4 IIS 7 Release Mode I tried changing directories, and changing permissions to no avail. I even tried enabling the internal logging but even that didn't work! No failures, no exceptions, nothing! After doing some more

NLog not writing to eventlog .NET Core 2.1

陌路散爱 提交于 2019-12-06 16:05:31
I've added NLog to my .NET core console app and it works with file and database targets. However when i try and get it to work with eventviewer it doesn't log anything. When i add the code for the eventviewer target the file and database part doesn't log anything. When I remove it, the logging starts working again. I have added a new event viewer source for the application using Powershell, so that wouldn't be the issue. The application doesn't crash or report an error, it runs fine but doesn't log anything when event viewer is included. <nlog xmlns="http://www.nlog-project.org/schemas/NLog

Configuring log4net to write to different files based on log level

雨燕双飞 提交于 2019-12-06 14:42:53
I'm setting up log4net and want to write debug messages in "debug.log", info messages in "info.log" and so on. To this end, I use several appenders, such as: <appender name="DebugLogger" type="log4net.Appender.RollingFileAppender"> <file value="..\Logs\Debug.log" /> <threshold value="DEBUG" /> <appendToFile value="true" /> <rollingStyle value="Size" /> <maxSizeRollBackups value="10" /> <maximumFileSize value="1MB" /> <staticLogFileName value="true" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />

.net core 2.1 Nlog.Web.AspNetCore

偶尔善良 提交于 2019-12-06 14:27:23
1、先创建 .net core Web 应用程序,选择API 2、安 装 Nuget 包:Nlog.Web.AspNetCore install-package Nlog install-package Nlog.Web.AspNetCore 或者打开Nuget管理界面搜索Nlog.Web.AspNetCore(我安装的版本是V4.9.0) 3、添加配置文件: nlog.config 注意,此处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" autoReload="true" internalLogLevel="Info" internalLogFile="c:\temp\internal-nlog.txt"> <!-- enable asp.net core layout renderers --> <extensions> <add assembly="NLog.Web.AspNetCore"/> </extensions> <!-- the targets to

NLog is not writing to database table

試著忘記壹切 提交于 2019-12-06 14:16:51
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 App" log="Application" layout="${date}: ${message} ${stacktrace}" /> <target name="databaselog" type=

Creating folder for log files for NLog with InnoSetup

别来无恙 提交于 2019-12-06 13:36:16
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 application directory, so even when the application is run by non-administrators, NLog has sufficient

Display NLog trace in RichTextBox

荒凉一梦 提交于 2019-12-06 12:25:42
问题 I whant to display NLog trace into RichTextBox at the same time when app executes logger.Trace("This is a Trace message"); logger.Debug("This is a Debug message"); logger.Info("This is an Info message"); logger.Warn("This is a Warn message"); logger.Error("This is an Error message"); logger.Fatal("This is a Fatal error message"); Has NLog any global event so it is possible to use it and populate RichTextBox ? Thank you! 回答1: We have to install https://www.nuget.org/packages/NLog.Windows.Forms

Protecting an email password when using NLog

纵饮孤独 提交于 2019-12-06 10:26:29
问题 When using NLog as a logging instrument we can easily send messages via email, for example this is the example configuration for using Gmail as a smtp server: <targets> <target name="gmail" type="Mail" smtpServer="smtp.gmail.com" smtpPort="587" smtpAuthentication="Basic" smtpUsername="user@gmail.com" smtpPassword="password" enableSsl="true" from="emailaddress@gmail.com" to="recipient@example.com" cc="alice@example.com;bob@example.com;charlie@example.com" /> </targets> <rules> <logger name="*"

NLog: Force BufferingTargetWrapper to empty on AppDomain UnhandledException

柔情痞子 提交于 2019-12-06 10:01:08
I have NLog configured in my application to to use the BufferingTargetWrapper for sending emails with the MailTarget . The problem I'm running into is I can not find a way to force NLog to empty the BufferingTargetWrapper before the application exits from Unhandled Exceptions. I tried calling LogManager.Flush() and LogManager.DisableLogging() from the Current App Domain's UnhandledException Event but it does not seam to work. What would I need to do to make it send the emails? you can call the BufferingTargetWrapper and force it to write the logs. Its strange that the LogManger.Flush doesn't