Menu
  • HOME
  • TAGS

Nlog file not writing

c#,.net,nlog

Check whether your process has write access to the ${basedir} location. Also, if your application is running from a special folder, make sure the process is running elevated.

Can't get NLog 2.0.1 version from NUGet

dll,nuget,nlog,servicestack-bsd

Try NLog version 2.0.1.1 or 2.0.1.2 from NuGet. The NLog assembly in those packages has a version of 2.0.1.0...

NLog try another target when main target failed to log

nlog

Ok, I found out how to do it. The key is to use FallbackGroup as type of a target, and place the targets in correct order inside. Example: <target xsi:type="FallbackGroup" name="f" returnToFirstOnSuccess="true"> <target xsi:type="File" name="f" fileName="${basedir}/logs/${processname}-${shortdate}.log" layout="${longdate} ${uppercase:${level}} ${message}" /> <target xsi:type="EventLog" name="eventLog" layout="${longdate} ${uppercase:${level}} ${message}" source="MySource" log="Application" /> </target>...

.NET Object creation causing memory spike and doesn't go away

.net,performance,memory-management,memory-leaks,nlog

Do I need to add IDisposable to all these poco classes so they are removed right away? Anything that implements IDisposable should have IDisposable.Dispose() called as soon as the object is no longer needed. Typically the best way do accomplish that is with a using statement. IDisposable is there...

Wrapping Logging Frameworks

.net,logging,log4net,enterprise-library,nlog

By using a wrapper around your different logging frameworks you will only using the common functions of the logging frameworks. Each logging framework has its strong and weak points, in most cases you should choose the logging framework based on the requirements for logging and look at those points.

NUnit keeps running the wrong version of a .dll

c#,nunit,inversion-of-control,castle-windsor,nlog

Adding the following to the .nunit project file fixes this issue: configfile="Hl7ic.Engine.Test.dll.config" Even though the above runtime config setting was properly set in the test.dll.config, the nunit project didn't know to use the test.dll.config file. I always thought it was implicitly known to nunit, but apparently it needs to be...

Nlog Error(message, exception) ignore exception

exception,error-handling,.net-3.5,nlog

Nlog is using sepecial methods for logging exceptions which are using the <loglevel>Exception naming schema. So in your case you need to use the ErrorException method in order to your exceptions get logged correctly: private static Logger _logger = LogManager.GetCurrentClassLogger(); _logger.ErrorException("my message", new Exception("my exception")); ...

Nlog from an internal nuget library package

c#,asp.net,nuget,nlog

Most likely you made some error in your nlog.config but ... Please check if the NLog.dll versions you are using are the same (so, the version you build your MyLibrary.dll with and your WebFormsProject). Mind that as of NLog version 3.0, the support for dotnetfx20 has been dropped. dotnetfx35 is...

Is this the correct way to log to a specific target with NLog?

c#,nlog

You always can create another logger instance where you want with specified name of target. What is the problem? For example I want to make an extended logging into a separate file. Than I go and create <rules> <logger name="ExtendedLogging" minlevel="Trace" writeTo="extendedLogging"/> </rules> <targets> <target name="extendedLogging" > <target xsi:type="File" fileName="C:/Logs/ExtendedLog${shortdate}.log"...

How to configure NLog (Servicestack) for Multiple files

c#,servicestack,nlog

You should be able to simply use ${threadid} (or if you name your threads, ${threadname}) in the filename layout. This will automatically separate log entries into one file for each thread. <target name="mynewlogfile" xsi:type="File" fileName="${basedir}/logs/mynewlogfile-thread-${threadid}.log" ... layout="${longdate}|${callsite}|mynewlogfile|${message}" /> ...

How to mark exception as logged (and log it only once)?

c#,.net,exception-handling,nlog

Only catch it once. It doesn't matter how far up the call stack that is: the Stack Trace will be accurate. It's when you catch and rethrow and catch again that the Stack Trace gets changed. Catch it once, log it, handle it as you can and then don't throw...

What's the meaning of the time stamp in nlog when async is on?

c#,.net,timestamp,performance-testing,nlog

According to the NLog source: https://github.com/NLog/NLog/blob/master/src/NLog/Logger.cs the LogEventInfo objectc is created at the time of the logging call (and is timestamped at that point). The writing of the LogEventInfo object is then written, asynchronously, to the appropriate target(s). So, the timestamp in the logfile should represent the timestamp of...

NLog use in MVC applicaiton

asp.net-mvc,nlog

Since you've already captured the error and you can't show the requested page, you could redirect within the catch to your error page: catch (Exception e) { logger.Error("Error in Index: " + e); return RedirectToAction("Index", "Error"); // Redirect to error controller or page } Alternatively, and probably more appropriate, you...

NLog - disable a specific logger

nlog

Adding final="true" to the class will tell it to stop running thru the rest of the rules when that one is hit. Because of this, the order in which you define the rules may be important as well in case you wanted more then one rule to hit but not...

NLog Instance issue

c#,nlog

When using the GetLogger method on NLog you get the instance you have configured in your configuration. If you need multiple configuration like writing to different files which are known at runtime, you need to create the log instances in code: if (!_terminalLogs.ContainsKey(filename)) { var config = LogManager.Configuration; var fileTarget...

NLog logging LogEventInfo and Exception data with one call

c#,asp.net-mvc,visual-studio,error-handling,nlog

You just need to set the Exception property to your exception on the LogEventInfo object: Exception ex = Server.GetLastError(); Logger logger = LogManager.GetCurrentClassLogger(); LogEventInfo eventInfo = new LogEventInfo(LogLevel.Trace, "Hello from RunJob", logger.Name); eventInfo.Properties["CustomerID"] = "someCustID"; eventInfo.Properties["TargetSite"] "someTargetSite"; eventInfo.Exception = ex; //set the exception for the eventInfo logger.Log(eventInfo); ...

UIImageView image not returning nil but image not showing

uiimageview,uiimage,nsurl,nlog,nil

It must be that you didn't create the image view when the first time you access the view of UIViewController. Note that self.view will trigger viewDidLoad method if it is nil, but then the imageView is nil. So you'b better create the imageView in viewDidLoad method.

Add NLog provider to ILoggerFactory

dependency-injection,nlog,asp.net-5

There's a logging sample in the ASP.NET GitHub repo that shows how to use NLog: https://github.com/aspnet/Logging/tree/dev/samples/SampleApp The sample uses a sample NLog logging adapter from here: https://github.com/aspnet/Logging/tree/dev/src/Microsoft.Framework.Logging.NLog Here's the project.json file from the app: https://github.com/aspnet/Logging/blob/dev/samples/SampleApp/project.json { "dependencies": { "Microsoft.Framework.Logging": "1.0.0-*", "Microsoft.Framework.Logging.Console": "1.0.0-*" }, "frameworks": { "aspnet50": {...

.NET external DLL log redirection

.net,logging,dll,nlog,console-redirect

For whomever this might help - here is the solution for this :) Nice! http://gabesworkshop.googlecode.com/svn/trunk/miniws/ConsoleReading/ConsoleRedirector.cs

App Config Connection String Not Updating For Service

c#,web-services,connection-string,app-config,nlog

Try an IIS reset as the connection string may be cached.

Should I inherit the class logger when using NLog?

c#,nlog

You should use a new one. LogManager.GetCurrentClassLogger creates a logger whose name is the current class. If you use the parent's class logger, you lose the information of the class doing the logging, it would appear as if the logging was done by the parent class. Most of the time,...

Nlog 3.1 with Castle Windsor not logging

c#,castle-windsor,nlog

You need to put the Logger property to every class where you want to log something and the instances of the class has to be created/managed by Windsor. So you need to add it to your controller: public class MyController : Controller { private ILogger logger = NullLogger.Instance; public ILogger...

NLog and Common.Logging nightmare

nlog,common.logging

Okay, so after all the fixes above I had to also update the Common.Logging package to v2.2.0.0 and then update the binding redirects manually. This is really a sub-optimal deployment of the Common.Logging.NLog20 nuget package. You shouldn't have to do this.

Turn off Logging during Release from Nlog.config

nlog

<nlog globalThreshold="Off" /> ...

NLOG varialble fileName and archiveFIleName

nlog

Yes, you can use any ${variable} as many times as you want. ... archiveFileName="${logger}.{#####}.csv" ... Take look at Archival options and Size/time-based file archival in the NLog documentation for more information...

NLog breaks when using operator '<'

.net,visual-studio,nlog

Am I missing something? Yup, you're not taking into account that this is XML, where < needs to be escaped. You want: <logger name="*" minlevel="Trace" writeTo="logFile"> <filters> <when condition="contains('${logger}','Domain.Messaging.') and level &lt; LogLevel.Warn" action="Ignore" /> </filters> </logger> From section 2.4 of the XML 1.0 specification: The ampersand character (&)...

Writing to .config files

asp.net-mvc,web-config,configuration-files,nlog

You can change settings programmatically in NLog, but you can't serialize those settings to the XML, yet. What you can do: Save the setting to the <appSettings> when changed read the <appSettings> when needed. eg using System.Web.Configuration; using System.Configuration; Configuration config = WebConfigurationManager.OpenWebConfiguration("/"); config.AppSettings.Settings["NlogConnectionString"].Value = "NewValue"; config.Save(ConfigurationSaveMode.Modified); Edit the connectionstring...

Buffered Emailing Logger for .Net (preferably a NLog Target)?

c#,email,logging,nlog

Take a look at the BufferingWrapper target. A target that buffers log events and sends them in batches to the wrapped target. You can use it in combination with the Mail target. <target xsi:type="BufferingWrapper" name="mail_buffered" bufferSize="5"> <target xsi:type="Mail" ... > ... </target> </target> ...

Logging to NLog in Hangfire.io

c#,nlog,hangfire

I have managed to solve this issue by using the following versions of nuget packages: NLog - 3.1 Common.Logging - 2.2.0 JVW.Logging.CommonLoggingNLogAdapter - 1.0.0.1 and then configuring the logging as such var properties = new NameValueCollection(); properties["configType"] = "INLINE"; Common.Logging.LogManager.Adapter = new NLogFactoryAdapter(properties); ...

LogManager.configuration is null

nlog

Copy NLog.config to the Test projects top level folder Add DeploymentItemAttribute to test classes (more info): : [TestClass] [DeploymentItem("ProjectName\\NLog.config")] public class GeneralTests Alternatively, you can load the configuration programmatically: LogManager.Configuration = new XmlLoggingConfiguration("c:\path\to\NLog.config")...

Filtering targets in NLog

nlog

Thanks for the reply. I have found the solution. FilteringWrapper - https://github.com/NLog/NLog/wiki/FilteringWrapper-target. It applies filter for target instead of filter for logger. <target xsi:type="FilteringWrapper" condition="'${event-context:item=Status}'=='Success'" name="rabbitMQFilteringTarget"> <target xsi:type="RabbitMQ" name="rabbitMQTarget" ... </target> </target> ...

How to log a message correlation Id with ServiceStack.Logging ILog?

logging,servicestack,nlog

Is there away to get the correlationId to be a first class citizen/property so that Seq will let me query by it? According to this it states "you can't used named properties in your NLog messages for querying in Seq, the @0 and @1 placeholders can be used in queries...

Common.Logging.NLog32 unable to use NLog 3.2.1.0? On client only?

c#,wpf,client,nlog,common.logging

Well that was strange... A colleague asked me to try using NLog directly without the Common.Logging wrapper. I did and everything worked as expected. After that I built back the code and wanted to reproduce the issue to post it as such on it´s github page. And it worked, no...

nlog renderer for types other than the Layout (for target attributes)

layout,config,nlog,renderer

I resolve this issue using custom Target derived from MailTarget: [Target("MyMail")] class MyMailTarget : MailTarget { /// <summary> /// Wrapper for enum to use placeholders /// </summary> [DefaultValue("None")] public Layout SmtpAuth { get; set; } protected override void Write(NLog.Common.AsyncLogEventInfo logEvent) { Write(new[] {logEvent}); } protected override void Write(NLog.Common.AsyncLogEventInfo[] logEvents) {...

Adding prefix to some targets in NLog

c#,nlog

You can use the ${logger} renderer to output the current logger name in your logfile layout. So you need something like: <targets> <target xsi:type="File" name="logfile" fileName="logfile.log" layout="${longdate} ${logger} ${level} ${message}" /> </targets> <rules> <logger name="*" minlevel="Info" writeTo="logfile" /> </rules> ...

How to set a fault tolerante channel between nlog and nxlog?

nlog,nxlog

I took b0ti's suggestion and came up with: var file = new FileTarget { FileName = @"C:\Logs\file.log", ArchiveFileName = @"C:\Logs\file.{#}.log", ArchiveEvery = FileArchivePeriod.Minute, ArchiveAboveSize = 2 * 1024 * 1024, // 2MB. ArchiveNumbering = ArchiveNumberingMode.Sequence, MaxArchiveFiles = 60, }; Nxlog watches only the archived file: C:\Logs\file.{#}.log Nlog will add a...

Using NLog with ModernUI on Windows 8.1

windows-8.1,nlog

System.Collections.CollectionBase is not a supported namespace in WinRT: http://msdn.microsoft.com/en-us/library/windows/apps/hh454064.aspx There are a couple of solutions, neither of which I've used so I can't personally recommend, but you can try out: 1) https://code.msdn.microsoft.com/Logging-Sample-for-Windows-0b9dffd7 2) https://github.com/mbrit/MetroLog...

To implement the max level programmatically in condition

.net,logging,nlog

We can do the following: filter.Action = FilterResult.Ignore; filter.Condition = "(level == LogLevel.Trace or level == LogLevel.Warn or level == LogLevel.Error or level == LogLevel.Fatal)" ...

Using NLog with multiple app instances

.net,clickonce,nlog

Within the context of your application, can you know a valid (and meaningful) name for that instance? Can the multiple instances be launched with a command line parameter that represents the name of the application? If you can "know" a useful name for the application, then you could store the...

Send logs in separate emails

nlog

Sorry, but this is impossible by default, and you can verify this by link: https://github.com/NLog/NLog/blob/master/src/NLog/Targets/MailTarget.cs#L282-L289. But you always can create own NLog target https://github.com/nlog/nlog/wiki/How-to-write-a-Target, based on MailTarget....

Correlating log messages within scope

c#,log4net,trace,nlog

You are looking for nested diagnostic context (NDC): Log.Info("Logging one level down"); using(ThreadContext.Stacks["NDC"].Push( requestid)) { Log.Info("Another message"); } Log.Info("Back from scope"); To get the scope in your log output use %property{NDC} in your conversion pattern: <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" /> log4net.ThreadContext.Stacks log4net.NDC (deprecated)...

NLog not working with Application Insights

nlog,ms-application-insights

Please upgrade to the latest version (currently 0.17.0) of the Microsoft.ApplicationInsights.NLogTarget NuGet package and its dependencies.

Nlog ${event-context:item=xxxx} not writing in logging database

c#,asp.net,nlog

As it turned out, it was a bug (or a feature) in NLog. When writing to a 'target' in NLog asynchronously the original LogEventInfo that is written is added to the Parameters collection of a new LogEventInfo, thus the Properties collection where the {event-context} gets its values from is empty...

How do I use Microsoft Application Insights with NLog (Target cannot be found: 'ApplicationInsights')

c#,logging,nlog,visual-studio-online,ms-application-insights

Solution: (thanks to @nemesv for the tip) Programmatically add the target with ConfigurationItemFactory.Default.Targets.RegisterDefinition( "ApplicationInsightsTarget", typeof(Microsoft.ApplicationInsights.NLogTarget.ApplicationInsightsTarget) ); and use it with <target name='ai' xsi:type='ApplicationInsightsTarget' /> ...

logging to oracle with nLog

asp.net-mvc,database,logging,odp.net,nlog

I solved this problem. The reason was wrong default value of commandType. By the unknown reason, initial value of commandType was assigned as 0, despite its default value is 1(COMMANDTYPE.TEXT) by the code(https://github.com/NLog/NLog/blob/master/src/NLog/Targets/DatabaseTarget.cs) Anyway I modified my configuration to set the commandType as 'Text'. And it works fine now. <target...