nlog

Set Event ID per log when writing to Windows Event Log

混江龙づ霸主 提交于 2019-12-01 09:03:21
I've got the EventLog target set up like so: <target xsi:type="EventLog" name="EventLog" layout="${longdate:universalTime=true}|${level:uppercase=true}|${logger}|${message}" source="MyApp" log="Application" /> Now, obviously not all my events will have the same ID, so I want to set event ID on a per message basis, rather than setting a static ID in the config. I believe this should work: var logger = LogManager.GetCurrentClassLogger(); var logEvent = new LogEventInfo(LogLevel.Warn, logger.Name, "Test message"); logEvent.Properties.Add("EventID", 4444); logger.Log(logEvent); ...but my events

Set Event ID per log when writing to Windows Event Log

為{幸葍}努か 提交于 2019-12-01 07:04:48
问题 I've got the EventLog target set up like so: <target xsi:type="EventLog" name="EventLog" layout="${longdate:universalTime=true}|${level:uppercase=true}|${logger}|${message}" source="MyApp" log="Application" /> Now, obviously not all my events will have the same ID, so I want to set event ID on a per message basis, rather than setting a static ID in the config. I believe this should work: var logger = LogManager.GetCurrentClassLogger(); var logEvent = new LogEventInfo(LogLevel.Warn, logger

Logging with NLog into an Isolated Storage

空扰寡人 提交于 2019-12-01 05:38:51
问题 I use the NLog Libary (http://nlog-project.org/) within my C# Win Forms to do the logging. Has anyone some experiance if it's possible to write the Logfile into an "IsolatedStorage" with this NLogger? Thx 4 answers 回答1: I have not used NLog in Silverlight, but a new version, 2.0, has just been released into beta and it is usable in Silverlight (there are some examples on the website). I have not seen an Isolated Storage Target, but I bet it would not be difficult to write one. This link shows

Automatically log System.diagnostics.trace messages to an Nlog target

元气小坏坏 提交于 2019-12-01 03:40:38
Say you have C# trace messages all over an application. Something like: Trace.TraceInformation("Service Started"); How do you automatically log this to an nLog target without having to add code like the following to all the classes that have trace messages? using NLog; private static Logger logger = LogManager.GetCurrentClassLogger(); Is there a way to do this without including traces produced by the .NET Framework itself, which this article demonstrates how to do? This works for cases where there isn't an explicit source <system.diagnostics> <trace autoflush="true" indentsize="4"> <listeners>

Better TypeInitializationException (innerException is also null)

懵懂的女人 提交于 2019-11-30 22:48:00
问题 Intro When an user creates a mistake in the configuration of NLog (like invalid XML), We (NLog) throw a NLogConfigurationException . The exception contains the description what is wrong. But sometimes this NLogConfigurationException is "eaten" by a System.TypeInitializationException if the first call to NLog is from a static field/property. Example E.g. if the user has this program: using System; using System.Collections.Generic; using System.Linq; using NLog; namespace

Wiring and injected NLog into a .Net Core console application

此生再无相见时 提交于 2019-11-30 22:33:42
问题 I created a consumer/job that I will have running as a process on linux written in C#. The process will: Read a message from RabbitMQ Make changes to the database Log any errors All the documentation on nlog about .net core are on aspnet core. When I try to get an ILogger implementation, it returns null. Here is an except of wiring and usage: static void ConfigureServices() { string environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); var builder = new

How can I use a RichTextBox as a NLog Target in a WPF application?

荒凉一梦 提交于 2019-11-30 20:27:09
I read the following posts but neither helped to just get the same efficient way of printing logs from NLog onto a RichTextBox control target as in Winforms. How can I use NLog's RichTextBox Target in WPF application? WPF: Binding RichTextBox to Logger Output I also browsed the official forum but with no success (except suggestions to read the two above posts). The idea would be to add the target as: <target xsi:type="RichTextBox" name="console" layout="${longdate:useUTC=true}|${level:uppercase=true}|${logger}::${message}" autoScroll="true" maxLines="1000000" controlName="rtbConsole" formName=

What is the best way of using NLog with MEF?

不问归期 提交于 2019-11-30 14:57:40
I am wondering what is the best way to use NLog with Managed Extensibility Framework (MEF)? I have an application that support plugins using MEF architecture (Import and Exports etc) I want to add logging capability to my application. As a logging component I want to use NLog. What would you recommend? 1. Create a wrapper for NLog, i.e. additional plugin that configures NLog and exports functions like void Log(string level, string message) that other plugins importing 2. Every plugin should have it is own instance of NLog configured and used. (They all would write to the same file actually).

Logging Generated SQL with EF Core 2 and Nlog

故事扮演 提交于 2019-11-30 14:38:12
I'm getting a little confused with how to log the generated SQL with asp.net core 2 and EntityFrameworkCore 2 and the correct way to go about it. After reading the this link from the MS docs it is saying that I should add during the services configuration in the startup.cs using .UseLoggerFactory(<LoggerFactory>) . However, this seems outdated as when I look to add the logger I get this message; Could someone please tell me the best way to add the logger to log the SQL for debug purposes? I also plan to use Nlog going forward for all my logging as opposed to the built in logging facilities, I

nlog using the connectionStringName for database logging

会有一股神秘感。 提交于 2019-11-30 13:42:38
here is my nlog.config file. I have turned on the throwsException. <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true"> <targets> <target type="Database" name="databaseLog" dbProvider="sqlserver" connectionstring="server=.\SQLExpress;database=Movie;integrated security=true"> <commandText> INSERT INTO [Log] ([Description] , [Level] ) VALUES (@Description, @Level ) </commandText> <parameter name="@Description" layout="${message}"/> <parameter name="@Level" layout="${level}"/> </target> </targets> <rules> <logger