nlog

Why would one use ELMAH if the application is using NLog

一世执手 提交于 2019-12-04 16:46:24
问题 I have to write a centralized logging framework. Basic requirements are: Log exceptions as well as other details if needed to SQL Server DB. If DB is down i.e. a failover option is to log to a file and email I had done some reading around and looks NLog is the best option being simple and most features I need. My plan is to write a wrapper class library around NLog and use my library in all my asp.net applications, web api as well as other library projects and some classic asp sites using COM

Protecting an email password when using NLog

好久不见. 提交于 2019-12-04 16:02:22
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="*" minlevel="Debug" writeTo="gmail" /> </rules> It works like a charm. But in the above example the

C# NLog日志框架

主宰稳场 提交于 2019-12-04 15:09:22
1、首先下载NLog框架,在vs NuGet中搜索NLog,下载安装NLog.Config 2、配置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" xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd" autoReload="true" throwExceptions="false" internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log"> <!-- optional, add some variables https://github.com/nlog/NLog/wiki/Configuration-file#variables --> <variable name="myvar" value="myvalue"/> <!-- See https://github.com/nlog/nlog/wiki

NLog time formatting

时光毁灭记忆、已成空白 提交于 2019-12-04 15:00:11
问题 How do I write a layout for NLog that outputs time with milliseconds like this 11:32:08:123 ? I use ${date:format=yyyy-MM-dd HH\:mm\:ss} but I need more time precision in my logs. 回答1: ${date:format=yyyy-MM-dd HH\:mm\:ss.fff} According to the NLog documentation, you can use C# DateTime format string. This is a pretty good reference for DateTime format strings: http://www.geekzilla.co.uk/View00FF7904-B510-468C-A2C8-F859AA20581F.htm 回答2: ${longdate} Another alternative to the format suggested

Configure log4net or NLog with XML from code

久未见 提交于 2019-12-04 12:50:14
Recently I have been working on a project where, among other things, we want to provide a centralized configuration system. We are using WCF, Silverlight, C#, etc to create a distributed system of services and clients. One of the things that we will want to configure is logging. Obviously, we can configure log4net or NLog via the app.config or via a separate logging configuration file. We can also configure via code. I wanted to see if it was possible to configure via XML from code. In other words, imagine that you have in memory (maybe read from a database?) the entire XML required to

Dependency Injection With NLog

那年仲夏 提交于 2019-12-04 12:02:51
问题 I've got a .Net core web app that I'm trying to add logging to via NLog. In previous projects, I've just used something like the following at the top of every class: private static Logger logger = LogManager.GetCurrentClassLogger(); I've trying to follow more best practices with this project where possible. My question is, how can I inject a logger which has the fully qualified name of the class that it's being injected into? In my startup.cs file, so far I've got the following: services

NLog, Elmah + shared library

夙愿已清 提交于 2019-12-04 11:22:47
I am trying to come up with a way to create a common library for all my MVC projects. I started off really simple with BaseController and BaseModel classes. Easy stuff! Now in my projects I would like to either use Elmah or NLog for logging exceptions and/or tracing info. Can anyone give me some ideas on the best practices for writing a common library to support both? I would use NLog as base for your logging. I've created a small target for NLog which could be used to route exceptions to ELMA. You'll find it at https://github.com/ccellar/nlog-elmah-target . With this target you are able to

Prevent NLog from rendering inner text when layout render output is empty

血红的双手。 提交于 2019-12-04 11:19:07
I put the contents of my NLog error email text into a file and render it using a a FileContents renderer. What I'd like to do is hide certain parts of html output if a layout renderer produces an empty string <div>Request ticket: ${httpContextItems:key=RequestTicket}</div> I am not sure of the syntax of the when condition/property . Here are some attempts: ${httpContextItems:key=RequestTicket:when:length>0} <div>Request ticket: ${httpContextItems:key=RequestTicket}</div> ${??? How to enclose? } And NLog doesn't like this nested stuff: ${when:when=length(${httpContextItems:key=RequestTicket})=0

NLog: Format loglevel with Whitespaces

旧巷老猫 提交于 2019-12-04 10:20:10
问题 I am using NLog for logging. Currently my Layout-String is: "${date:format=dd.MM.yyyy HH\\:mm\\:ss,fff} | ${level:uppercase=true} | ${message}" This results in the following Logs: 18.12.2013 11:23:14,834 | INFO | this is an info 18.12.2013 11:23:14,835 | TRACE | this is a trace What I want now is to format the "$level" to fill up with Whitespaces so that it looks like a table with 5 Characters. I would like to have: 18.12.2013 11:23:14,834 | INFO | this is an info 18.12.2013 11:23:14,835 |

Having NLog loggers with different configuration

佐手、 提交于 2019-12-04 10:03:32
问题 In NLog is possible to create multiple loggers with different configuration? I have a component that every time that is instanced must log all events to a different file that is related to the new instance. Is this possible with NLog? If not, there are logging frameworks that do that? 回答1: Yes, you can do that. You can either configure the logger for that type to log to a specific target. Or you can configure the logger for that type to log to a target (such as a file), naming the file