nlog

ASP.NET MVC2 + Ninject + NLog (+ shared hosting?) = NullReferenceException

别说谁变了你拦得住时间么 提交于 2019-11-28 19:17:32
问题 I have an MVC2 app that's based on the Tekpub Starter Site, so it uses Ninject for dependency injection, NLog for logging, and a bunch of other libraries in various places. As far as I can tell though, it's these that are causing my problem. Everything works beautifully on my PC using the ASP.NET dev server (Cassini) but when I deploy to the server (it's a cheap shared hosting deal), I get a NullReferenceException that seems to be related to Ninject instantiating the logger. Here's the

NLog rotate and cleanup logfiles

廉价感情. 提交于 2019-11-28 18:40:18
Within my company we're working with NLog. We're experiencing issues with large amount of log files. What we want to do is archive files by day and keep a maximum of an x amount of files. Lets say 7. I've read several topics on the internet regarding this and they're mostly pointing me in the same direction of modifying my NLog.config file. However it doesn't seem to be willing to rotate the files as I expect it to do. Currently nothing is being archived in the desired folder. But all files are saved in the 'logs'-directory in the following format; Log.info.2011-11-07.txt Within my application

Use NLog in ASP.NET Core application

戏子无情 提交于 2019-11-28 18:16:40
I found a CodeProject with an example of how to get this to work, but it doesn't work. The main problem seems to be that the "Microsoft.Framework.Logging.NLog": "1.0.0-*" package doesn't seem to exist in Nuget. I've looked at this StackOverflow question and looked at the GitHub example it references, but it seems to contain the same issue. I've tried to get it working on my own and the best I've come up with is the following: public class NLogLogger : ILogger { public NLogLogger() { new WebLoggerConfigurer().ConfigureDefault(); } public void Log(LogLevel logLevel, int eventId, object state,

How to get the Stack trace when logging exceptions with NLog?

限于喜欢 提交于 2019-11-28 16:58:35
问题 When I use the default layout with NLog it only prints the name of the exception. I've been told that the log4jxmlevent layout doesn't prints nothing about the exception. What layout will help me? Example code: try { throw new SystemException(); } catch (Exception ex) { logger.Error("oi", ex); } Default layout output: 2011-01-14 09:14:48.0343|ERROR|ConsoleApplication.Program|oi log4jxmlevent output: <log4j:event logger="ConsoleApplication.Program" level="ERROR" timestamp="1295003776872"

How do I log a custom field in NLog to database?

£可爱£侵袭症+ 提交于 2019-11-28 14:44:16
问题 I currently use NLog on a lot of projects. On some, I log to a database. Here is what I would like to do: CREATE TABLE [dbo].[NLogEntries]( [Id] [bigint] IDENTITY(1,1) NOT NULL, [Origin] [nvarchar](100) NOT NULL, [LogLevel] [nvarchar](20) NOT NULL, [Message] [nvarchar](3600) NOT NULL, [CreatedOn] [datetime] NOT NULL, [OrderId] [int] NULL --Custom field! ) And NLog.config with this target: <target type="Database" name="database" connectionstring="Server=localhost;Database=NLog;Trusted

NLog doen't work on IIS

隐身守侯 提交于 2019-11-28 14:30:53
I added NLog to my project. Following the instructions I created 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"> <targets> <target name="file" xsi:type="File" layout="${longdate} ${logger} ${message}" fileName="${basedir}/${shortdate}.log" /> </targets> <rules> <logger name="*" minlevel="Debug" writeTo="file" /> </rules> </nlog> and then just log something. var logger = LogManager.GetCurrentClassLogger(); logger.Info("xxxx"); With the developer web server it work fine, but when I publish the

How to get NLog to write to database

匆匆过客 提交于 2019-11-28 14:29:33
问题 I'm trying to get NLog to log to my database log table but to no avail. I'm sure my connection string is correct because it's the same used elsewhere in my web.config. Writing out to a file works fine, so I know it's not just NLog, but must be something I'm doing wrong. Below is my NLog configuration: <!-- NLOG CONFIGURATION --> <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <targets> <target name="file" xsi:type="File"

Implementation and usage of logger wrapper for log4net

半腔热情 提交于 2019-11-28 11:26:20
This question is related to Steven ’s answer - here . He proposed a very good logger wrapper. I will paste his code below: public interface ILogger { void Log(LogEntry entry); } public static class LoggerExtensions { public static void Log(this ILogger logger, string message) { logger.Log(new LogEntry(LoggingEventType.Information, message, null)); } public static void Log(this ILogger logger, Exception exception) { logger.Log(new LogEntry(LoggingEventType.Error, exception.Message, exception)); } // More methods here. } So, my question is what is the proper way to create implementation that

ASP.NET Core系列:日志

醉酒当歌 提交于 2019-11-28 08:11:43
1. NLog   添加安装包: Install-Package NLog.Web.AspNetCore <?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"> <targets> <target name="file" xsi:type="AsyncWrapper" queueLimit="5000" overflowAction="Discard"> <target xsi:type="File" fileName="${basedir}/Logs/${shortdate}.log" layout="${longdate} ${level:uppercase=true} ${event-context:item=Action} ${message} ${event-context:item=Amount} ${stacktrace}" keepFileOpen="false" archiveFileName="${basedir}/Logs/${shortdate}.{##}.log"

using AppData location in NLog

怎甘沉沦 提交于 2019-11-28 07:56:39
My NLog targets is like this: <targets> <target xsi:type="Console" name="console" layout="${longdate}|${level}|${message}" /> <target xsi:type="File" name="ErrorLog" fileName="${basedir}/error.txt" layout="${longdate} Trace: ${stacktrace} ${message}" /> <target xsi:type="File" name="AccessLog" fileName="${basedir}/access.txt" layout="${shortdate} | ${message}" /> </targets> But this causes problems if the user isn't an admin on their machine, because they will not have write access to "Program Files". How can I get something like %AppData% to NLog instead of BaseDir? Oren Mazor You're looking