Quantcast
Channel: NLog - Advanced .NET Logging
Viewing all 60 articles
Browse latest View live

Commented Issue: CSV header written multiple times to File target [6370]

$
0
0
When setting up a file target with a CSV layout, the CSV header is written to the file at the moment the first log message is sent by the application since it has started.
Whether the file is empty or not, the CSV header is always rewritten after restarting the application.
 
Steps to reproduce:
=============
1) Create a console application that logs a single message with configuration file as below:
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>
<nlog autoReload="true">
<targets>
<target
name="AllMessages"
type="File"
fileName="${basedir}/log/TestLog.csv"
archiveFileName="${basedir}/log/TestLog{##}.csv"
archiveAboveSize="20971520"
maxArchiveFiles="10"
archiveNumbering="Rolling">
<layout type="CSVLayout">
<column name="Time" layout="${longdate}" />
<column name="Level" layout="${level}"/>
<column name="Logger" layout="${logger}"/>
<column name="Message" layout="${message}" />
</layout>
</target>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="AllMessages" />
</rules>
</nlog>
</configuration>
 
2) Run the application twice.
 
Proposed fix:
=========
 
I found a way to fix the problem by making a small change to the 2FileTarget.cs" file. It checks whether the file is empty before writing the header.
 
I replaced the following code at line 1082:
 
if (writeHeader && !justData)
{
byte[] headerBytes = this.GetHeaderBytes();
if (headerBytes != null)
{
appenderToWrite.Write(headerBytes);
}
}
By the following code:
 
if (writeHeader && !justData)
{
long fileLength = 0;
DateTime lastWriteTime;
 
// Only write header on empty files or if file info cannot be obtained
if (!appenderToWrite.GetFileInfo(out lastWriteTime, out fileLength) || fileLength == 0)
{
byte[] headerBytes = this.GetHeaderBytes();
if (headerBytes != null)
{
appenderToWrite.Write(headerBytes);
}
}
}
Comments: ** Comment from web user: GreenHex **

Where is the newest build? When I go to downloads the __latest nightly build is Jan 24, 2012, Alpha__

liam83 __wrote Sep 21, 2012 at 9:37 AM__

Has been fixed in the Github repository


Created Unassigned: [v2.0.0.2000] FileTarget.AutoFlush does not work [7620]

$
0
0
NLog v2.0.0.2000

Even if FileTarget.AutoFlush is set to true log messages are not flushed.
This issue has been discuses here as well:
https://groups.google.com/forum/#!msg/nlog-users/RAe_GTcC3LQ/L_PnpOmCm2cJ

Created Unassigned: Using LogReceiverService with targets async="true" floods the receiver service [7667]

$
0
0
Using version 2.1 of Nlog.
I have the following config in my app. Using Fiddler I noticed that I had 14 calls to http://vision.local.com/webservice/nlogreceiver.svc/binarylogger per second. If I set async to false I get calls only when I log an error.

The flooding occurs right after the following line in my code:
_logger = LogManager.GetCurrentClassLogger();

while I am still on my app's login screen so nothing has even happened yet. Is this a bug? Has anyone else seen this?

<targets async="true">
<!-- add your targets here -->
<target name="infofile"
xsi:type="File"
fileName="${basedir}/Logs/infolog.log"
archiveEvery="Day"
maxArchiveFiles="30"
archiveFileName="${basedir}/Logs/archives/infolog.{#}.log"
archiveNumbering="Date"
archiveDateFormat="yyyyMMdd"
concurrentWrites="false"/>
<target name="errorfile"
xsi:type="File"
fileName="logs/Errorlog.txt"
archiveEvery="Day"
maxArchiveFiles="30"
archiveNumbering="Date"
archiveDateFormat="yyyyMMdd"
archiveFileName="${basedir}/Logs/archives/Errorlog.{#}.log"

concurrentWrites="false"/>

<target xsi:type="LogReceiverService"
name="LogReceiver"
endpointAddress="http://vision.local.com/webservice/nlogreceiver.svc/binarylogger"
useBinaryEncoding="true"
includeEventProperties="true"
clientId="${machinename}">
<parameter name="message" type="System.String" layout="${message}"/>
<parameter name="logger" type="System.String" layout="${logger}"/>
<parameter name="level" type="System.String" layout="${level}"/>
<parameter name="client" type="System.String" layout="${machinename}"/>
</target>>
</targets>

<rules>
<!-- add your logging rules here -->
<logger name="*" maxlevel="Info" writeTo="infofile" />
<logger name="*" minlevel="Warn" writeTo="errorfile" />
<logger name="*" minlevel="Error" writeTo="LogReceiver" />

</rules>
</nlog>

Commented Issue: Async Wrapper is not working [7422]

$
0
0
Hi All,

We are getting different behaviors when enabling Aync logging by using AsyncWrapper. As I know there are 2 ways to enable this.

1. by using <targets async =" true">
2. by providing a new target by using <target name="asyncWrapper" xsi:type="AsyncWrapper" queueLimit="5000" overflowAction="Grow">

The option 1 is fast and i can see that my logs are written on a different thread. I can see that 50000 log messages are being written when program control comes back. The only problem here is, log messages are lost.

The option 2 is not at all working. It seems that NLog writes messages synchronously and doesn't return control.

Are we missing any NLog specific configuration for option number 2?

Attached is the configuration file I am using.

Thanks,
Comments: ** Comment from web user: johnnyjob **

I noticed lost messages too in NLog 2.0. This framework just drives me crazy, considering migration from it in the nearest future. Serious bugs are not fixed for months.

Commented Issue: Data loss when applying concurrentWrites and keepFileOpen [7425]

$
0
0
Hi,

Consider following scenario.

1. I am starting 5 applications logging 30,000 messages each.
2. I am expecting 1,50,000 messages at the end in the log files. Applications are sharing the same log file destination.
3. I am leveraging concurrentWrites = true and keepFileOpen = true. Now the problem is, we are not getting 1,50,000 messages logged at the end.

We have around 1,30,000 messages and other messages are lost. I am closing all applications once all logs are written to the file and I am also calling LogManager.Flush(); at the end.

Are we missing any configuration here? Attached is my configuration.
Any help in this direction would be great!

Thanks
Comments: ** Comment from web user: johnnyjob **

And try to remove your log file manually - you'll see new log messages are not logged anymore, until you restart a process. I reproduced it in NLog 2.0 and in 2.1 in a test application, but feel too lazy to post a new issue here because other issues I posted haven't been addressed for months.

Created Unassigned: LogConfiguration from Stream [7711]

$
0
0
Hello,

for my application I would prefer loading the NLog configuration from Stream (as I would likely embed it into my application instead of laying it into the appliaction root folder).

Would be nice if this would be implemented :) Shouldn't be that big problem to add this.

Thanks :)

Created Unassigned: Possible memory leak in NLOG [7760]

$
0
0
Hello,
while performing a memory leak profiling session on an existing app, I've discovered that NLog seems to leak on the NLog.Internal.Fakables.AppDomainWrapper, I've created a simple projects that shows this..
after some time the number of instances rooted increase... can anyone help me on this?
Thanks

Commented Issue: Support logging via ETW [4546]

$
0
0
Support logging via ETW
Comments: ** Comment from web user: consept **

Till this request is resolved you may use my extension Nuget package for NLog: LowLevelDesign.NLog.Ext - it contains two ETW targets (one based on System.Diagnostics.Eventing and other based on Microsoft.Diagnostics.Tracing). I described how to use them on my blog: http://lowleveldesign.wordpress.com/2014/04/18/etw-providers-for-nlog/.


Created Unassigned: Unable to find configuration file in VS extension [7840]

$
0
0
Hello,
I'm working on a Visual Studio extension.
NLog picks up nlog.config only from C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE because that's where devenv.exe (Visual Studio executable) is located.

I would like to to pick it up from C:\Users\(My username)\AppData\Local\Microsoft\VisualStudio\(VS version)\Extensions\(MyExtension name and version)\
that's where NLog.dll and rest of the extension is located, and that's where nlog.config is copied on build.

Is there an alternate way of loading the configuration? If not, is it ok if I go ahead and contribute? Would you be interested in pulling such feature?

Reviewed: NLog 2.0 (juil. 29, 2014)

$
0
0
Rated 5 Stars (out of 5) - Simple and flexible. Well done !

Commented Issue: Add please to NLog WpfRichTextBoxTarget [6272]

$
0
0
I had written this feature himself, b/c it urgently needed to me.
But I think team of NLog can do this much better.
I attach sources of WpfRichTextBoxTarget, WpfRichTextBoxRowColoringRule and WpfRichTextBoxWordColoringRule.
The logic of WpfRichTextBoxWordColoringRule is not realized in WpfRichTextBoxTarget.
 
Thanks,
Alexandr.
Comments: ** Comment from web user: gonzalocontento **

I created a sample project for those who need to see the changes in action.
Minor changes to accommodate for my taste ;-)

Commented Issue: Add please to NLog WpfRichTextBoxTarget [6272]

$
0
0
I had written this feature himself, b/c it urgently needed to me.
But I think team of NLog can do this much better.
I attach sources of WpfRichTextBoxTarget, WpfRichTextBoxRowColoringRule and WpfRichTextBoxWordColoringRule.
The logic of WpfRichTextBoxWordColoringRule is not realized in WpfRichTextBoxTarget.
 
Thanks,
Alexandr.
Comments: ** Comment from web user: gonzalocontento **

The sample file is WpfRichTextLogger.zip

Reviewed: NLog 2.0 (Sep 26, 2014)

$
0
0
Rated 5 Stars (out of 5) - Well organized library for logging in .NET applications. In most applications it should be easy to configure and use.

Created Unassigned: LoggingRule.ToString() error [7894]

$
0
0
The current ToString() overload for LoggingRule objects fails to show the configured log levels unless LogLevel.Trace is enabled. When Trace is not enabled, ToString() makes it appear that all of the other levels are turned off while debugging.

Created Unassigned: MethodAccessException when calling LogManager.GetCurrentClassLogger() [7922]

$
0
0
I'm getting an exception when I run a unit test on a controller in web project (ASP.NET web api). The exception is thrown when LogManager.GetCurrentClassLogger() of the controller is executed/
```
System.MethodAccessException: Attempt by method 'Castle.Proxies.ClaimsPrincipalProxy.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)' to access method 'Castle.DynamicProxy.Internal.TypeUtil.Sort(System.Reflection.MemberInfo[])' failed
```
it results in TypeInitializationException in LogManager.GetCurrentClassLogger()
here is the call stack:
```
at Castle.Proxies.ClaimsPrincipalProxy.GetObjectData(SerializationInfo, StreamingContext)
at System.Runtime.Serialization.ObjectCloneHelper.GetObjectData(Object serObj, String& typeName, String& assemName, String[]& fieldNames, Object[]& fieldValues)
at System.AppDomain.get_Evidence()
at System.AppDomain.get_Evidence()
at System.Configuration.ClientConfigPaths.GetEvidenceInfo(AppDomain appDomain, String exePath, ref String typeName)
at System.Configuration.ClientConfigPaths.GetTypeAndHashSuffix(AppDomain appDomain, String exePath)
at System.Configuration.ClientConfigPaths..ctor(String exePath, Boolean includeUserConfig)
at System.Configuration.ClientConfigPaths.GetPaths(String exePath, Boolean includeUserConfig)
at System.Configuration.ClientConfigurationHost.RequireCompleteInit(IInternalConfigRecord record)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, ref Object result, ref Object resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at NLog.Config.XmlLoggingConfiguration.get_AppConfig()
at NLog.LogFactory.get_Configuration()
at NLog.LogFactory.GetLogger(LoggerCacheKey cacheKey)
at NLog.LogFactory.GetLogger(String name)
at NLog.LogManager.GetCurrentClassLogger()
```

Commented Issue: Invalid configuration throws exception [7031]

$
0
0
When the NLog configuration is invalid LogManager.GetCurrentClassLogger throws an exception, even when throwsException is false (which is the default). NLog doesn't log this error to its internal error log file.
So, for the case of an invalid configuration I have to create some fallback mechanism that still allows me to log this error. Specifically, this means that I have to encapsulate the creation of the logger in a try catch block and either use low level means to create my own log file or create an NLog instance with default values in code.
Is this intended behavior?
Comments: ** Comment from web user: PapaCoen **

Hope you still look at these issues: I seem to have the same problem with NLog 3.1.0.0. When I use ${machine} instead of ${machinename} I get the following error:

```
System.Configuration.ConfigurationErrorsException: An error oc
curred creating the configuration section handler for nlog: Error when setting p
roperty 'FileName' on File Target[file] (...Export.exe.config line 11) ---> NLog.NLogCo
nfigurationException: Error when setting property 'FileName' on File Target[file
] ---> System.ArgumentException: LayoutRenderer cannot be found: 'machine'
at NLog.Config.Factory`2.CreateInstance(String name)
at NLog.Layouts.LayoutParser.ParseLayoutRenderer(ConfigurationItemFactory con
figurationItemFactory, SimpleStringReader sr)
at NLog.Layouts.LayoutParser.CompileLayout(ConfigurationItemFactory configura
tionItemFactory, SimpleStringReader sr, Boolean isNested, String& text)
at NLog.Layouts.SimpleLayout.set_Text(String value)
at NLog.Internal.PropertyHelper.TryNLogSpecificConversion(Type propertyType,
String value, Object& newValue, ConfigurationItemFactory configurationItemFactor
y)
at NLog.Internal.PropertyHelper.SetPropertyFromString(Object o, String name,
String value, ConfigurationItemFactory configurationItemFactory)
--- End of inner exception stack trace ---
at NLog.Internal.PropertyHelper.SetPropertyFromString(Object o, String name,
String value, ConfigurationItemFactory configurationItemFactory)
at NLog.Config.XmlLoggingConfiguration.ConfigureObjectFromAttributes(Object t
argetObject, NLogXmlElement element, Boolean ignoreType)
at NLog.Config.XmlLoggingConfiguration.ParseTargetElement(Target target, NLog
XmlElement targetElement)
at NLog.Config.XmlLoggingConfiguration.ParseTargetsElement(NLogXmlElement tar
getsElement)
at NLog.Config.XmlLoggingConfiguration.ParseNLogElement(NLogXmlElement nlogEl
ement, String baseDirectory)
at NLog.Config.XmlLoggingConfiguration.Initialize(XmlReader reader, String fi
leName, Boolean ignoreErrors)
at NLog.Config.XmlLoggingConfiguration..ctor(XmlElement element, String fileN
ame)
at NLog.Config.ConfigSectionHandler.Create(XmlNode section, IAppDomain appDom
ain)
at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactor
y.CreateSectionImpl(RuntimeConfigurationRecord configRecord, FactoryRecord facto
ryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader read
er)
at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactor
y.CreateSectionWithRestrictedPermissions(RuntimeConfigurationRecord configRecord
, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig,
ConfigXmlReader reader)
at System.Configuration.RuntimeConfigurationRecord.CreateSection(Boolean inpu
tIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object par
entConfig, ConfigXmlReader reader)
at System.Configuration.BaseConfigurationRecord.CallCreateSection(Boolean inp
utIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object pa
rentConfig, ConfigXmlReader reader, String filename, Int32 line)
--- End of inner exception stack trace ---
at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, Se
ctionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord
sectionRecord, Object parentResult)
at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factor
yRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boole
an getRuntimeObject, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String co
nfigKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Bool
ean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String co
nfigKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Bool
ean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String co
nfigKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Bool
ean requestIsHere, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at NLog.LogFactory.get_Configuration()
at NLog.LogFactory.GetLogger(LoggerCacheKey cacheKey)
at NLog.LogManager.GetCurrentClassLogger()
at
```

Took me half a day to figure out it was an error with the NLog configuration :)

Commented Issue: Invalid configuration throws exception [7031]

$
0
0
When the NLog configuration is invalid LogManager.GetCurrentClassLogger throws an exception, even when throwsException is false (which is the default). NLog doesn't log this error to its internal error log file.
So, for the case of an invalid configuration I have to create some fallback mechanism that still allows me to log this error. Specifically, this means that I have to encapsulate the creation of the logger in a try catch block and either use low level means to create my own log file or create an NLog instance with default values in code.
Is this intended behavior?
Comments: ** Comment from web user: PapaCoen **

Also throws the exception with throwExceptions="false"

Commented Issue: Invalid configuration throws exception [7031]

$
0
0
When the NLog configuration is invalid LogManager.GetCurrentClassLogger throws an exception, even when throwsException is false (which is the default). NLog doesn't log this error to its internal error log file.
So, for the case of an invalid configuration I have to create some fallback mechanism that still allows me to log this error. Specifically, this means that I have to encapsulate the creation of the logger in a try catch block and either use low level means to create my own log file or create an NLog instance with default values in code.
Is this intended behavior?
Comments: ** Comment from web user: PapaCoen **

Debugging shows the LogManager.ThrowsException property is set to 'false'.

Created Unassigned: Async Wrapper does not seem to be getting called [7972]

$
0
0
Hi,

One of the projects that I've joined is using NLog. Unfortunately some of the logging is taking longer than expected so I'm trying to write to the log asynchronously.

If I put async=true into targets then it is writing asynchronously and doesn't impede the main thread. However if I remove this and use AsyncWrapper then the write is slow again.

```
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<extensions>
<add assembly="NLog.Extended"/>
</extensions>
<targets>
<target name="AsyncInformation" xsi:type="AsyncWrapper" overflowAction="Block" queueLimit="1000000" batchSize="1000" timeToSleepBetweenBatches="0">
<target name="Information"
xsi:type="File"
fileName="C:\Logs\InformationLog.txt"
archiveFileName="C:\Logs\Archive\InformationLog.{#}.txt"
archiveAboveSize = "262144"
archiveNumbering="Rolling"
maxArchiveFiles="30"
layout="${message}"
concurrentWrites="true"/>
</target>
<target name="AsyncException" xsi:type="AsyncWrapper" overflowAction="Block" queueLimit="1000000" batchSize="1000" timeToSleepBetweenBatches="0">
<target name="Exception"
xsi:type="File"
fileName="C:\Logs\ExceptionLog.txt"
archiveFileName="C:\Logs\Archive\ExceptionLog.{#}.txt"
archiveAboveSize = "262144"
archiveNumbering="Rolling"
maxArchiveFiles="30"
layout="${message}" concurrentWrites="true"/>
</target>
</targets>
<rules>
<logger name="*" minlevel="Info" maxlevel="Info" writeTo="AsyncInformation"/>
<logger name="*" minlevel="Error" maxlevel="Error" writeTo="AsyncException"/>
</rules>
</nlog>
```

The logging code is:

```
_logger = NLog.LogManager.GetLogger("MyLogger");

ExceptionLogMessage newLogMessage = new ExceptionLogMessage(description, e,callingFunction);
_logger.Error(newLogMessage.Serialise);
```
I've tried different settings in AsyncWrapper, even the default, which I presume is what async=true is using but nothing seems to be produce the same result as async=true does. Which suggests to me that I'm not registering the AsyncWrapper correctly - but I can't find what I'm doing wrong.

Any suggestions?

Using NLog v2.0

Kind regards
Sidharth

Commented Unassigned: Async Wrapper does not seem to be getting called [7972]

$
0
0
Hi,

One of the projects that I've joined is using NLog. Unfortunately some of the logging is taking longer than expected so I'm trying to write to the log asynchronously.

If I put async=true into targets then it is writing asynchronously and doesn't impede the main thread. However if I remove this and use AsyncWrapper then the write is slow again.

```
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<extensions>
<add assembly="NLog.Extended"/>
</extensions>
<targets>
<target name="AsyncInformation" xsi:type="AsyncWrapper" overflowAction="Block" queueLimit="1000000" batchSize="1000" timeToSleepBetweenBatches="0">
<target name="Information"
xsi:type="File"
fileName="C:\Logs\InformationLog.txt"
archiveFileName="C:\Logs\Archive\InformationLog.{#}.txt"
archiveAboveSize = "262144"
archiveNumbering="Rolling"
maxArchiveFiles="30"
layout="${message}"
concurrentWrites="true"/>
</target>
<target name="AsyncException" xsi:type="AsyncWrapper" overflowAction="Block" queueLimit="1000000" batchSize="1000" timeToSleepBetweenBatches="0">
<target name="Exception"
xsi:type="File"
fileName="C:\Logs\ExceptionLog.txt"
archiveFileName="C:\Logs\Archive\ExceptionLog.{#}.txt"
archiveAboveSize = "262144"
archiveNumbering="Rolling"
maxArchiveFiles="30"
layout="${message}" concurrentWrites="true"/>
</target>
</targets>
<rules>
<logger name="*" minlevel="Info" maxlevel="Info" writeTo="AsyncInformation"/>
<logger name="*" minlevel="Error" maxlevel="Error" writeTo="AsyncException"/>
</rules>
</nlog>
```

The logging code is:

```
_logger = NLog.LogManager.GetLogger("MyLogger");

ExceptionLogMessage newLogMessage = new ExceptionLogMessage(description, e,callingFunction);
_logger.Error(newLogMessage.Serialise);
```
I've tried different settings in AsyncWrapper, even the default, which I presume is what async=true is using but nothing seems to be produce the same result as async=true does. Which suggests to me that I'm not registering the AsyncWrapper correctly - but I can't find what I'm doing wrong.

Any suggestions?

Using NLog v2.0

Kind regards
Sidharth
Comments: ** Comment from web user: sidharthnayyar **

Hi,

I've found the cause of the issue. There was another rule which was getting set which was causing the issue. I "async-ed" that and it's working similar to the async=true now.

Kind regards

Viewing all 60 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>