I am using CKFinder in ASP.NET. It has been working but has recently stopped (uploads specifically). While trying to track down the issues, I noticed no logs are being written.
In my web.config, I have enabled verbose logging for ckfinder:
enableVerboseLogging="true"
Here is my NLog.config file (which I am not familiar with; we use log4net). Other traces are being written via NLog, however, so I think this is correct.
<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets async="true">
<target xsi:type="File" name="logFile" fileName="${basedir}/App_Data/logs/ckfinder.log"
archiveFileName="${basedir}/App_Data/logs/archives/ckfinder.{#}.log" archiveEvery="Day" archiveNumbering="Rolling" maxArchiveFiles="5" concurrentWrites="true" keepFileOpen="false"
layout="${level} | ${logger} | ${longdate} | ${message}${onexception: | ${exception:format=ToString,StackTrace:maxInnerExceptionLevel=10}}" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="logfile" />
</rules>
</nlog>
I was forgetting this line from Startup.Configuration:
LoggerManager.LoggerAdapterFactory = new NLogLoggerAdapterFactory();
Related
I´ve got a Windows-Service which runs in the same location as its Notify. They communicate with WebSocketSharp.
But only one program has a log file. I think the problem is, the notify consumes the nlog.config at first and for the service the nlog.config is locked. But I may confuse it. Also always the Notify only produces the log, never the service. May be in my nlog.config is an error? But then why does the notify produce one but the Service not, when the service and the notify should use the same?
I've tested and the service does not produce any log, even the notify is not running.
May there be a problem with Windows Service and NLog?
Here my 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">
<time type="AccurateUtc" />
<targets>
<target name="debug-logfile" xsi:type="File" fileName="${specialfolder:folder=ApplicationData}/MyService/log/${date:format=yyyy-MM}.log" layout="${longdate} | ${level} | ${message}" />
<target name="trace-logfile" xsi:type="File" fileName="${specialfolder:folder=ApplicationData}/MyService/log/trace/${date:format=yyyy-MM-dd}.log" layout="${date:format=yyyy-MM-dd HH\:mm\:ss.fffffff} | ${level} | ${message}" />
<target name="errorfile" xsi:type="File" fileName="${specialfolder:folder=ApplicationData}/MyService/log/Error.log" layout="${longdate} | ${level} | ${message}" />
<target name="console" xsi:type="Console" layout="${longdate} | ${level} | ${callsite} | ${message}" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="trace-logfile" />
<logger name="*" minlevel="Debug" writeTo="debug-logfile" />
<logger name="*" minlevel="Error" writeTo="errorfile" />
</rules>
</nlog>
Here is how I use NLog:
protected static NLog.Logger Log = LogManager.GetCurrentClassLogger();
Log.Trace("Message");
I am using NLog to write logs to file, which is working fine. Now I want to write logs to Elasticsearch, so I added NLog.Targets.ElasticSearch in nugets package and I configured my Nlog.config file. Unfortunately, I can't see any log information while calling http://localhost:9200/_search
In NLog.config, I added extension and targets for Elasticsearch:
<extensions>
<add assembly="NLog.Extended" />
<add assembly="NLog.Targets.ElasticSearch"/>
</extensions>
<targets>
<target xsi:type="ElasticSearch"
name="elastic"
layout="${logger} | ${threadid} | ${message}"
includeAllProperties="true"
uri="http://localhost:9200"/>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="file" />
<logger name="*" minlevel="Trace" writeTo="elastic" />
</rules>
I expect Trace type NLog should be written in Elasticsearch. Am I missing something in the config file?
By the way, I checked this doc for parameters: https://github.com/ReactiveMarkets/NLog.Targets.ElasticSearch/wiki
I just added BufferingWrapper type and it worked. Some references to read:
https://github.com/markmcdowell/NLog.Targets.ElasticSearch/blob/master/src/NLog.Targets.ElasticSearch.Tests/App.config
https://github.com/nlog/NLog/wiki/BufferingWrapper-target
Additionally, please check ElasticSearch.Net latest version in NuGet package.
You can find NLog configuration for Elasticsearch below, which is working fine for me:
<extensions>
<add assembly="NLog.Extended" />
<add assembly="NLog.Targets.ElasticSearch"/>
</extensions>
<target xsi:type="BufferingWrapper" name="ElasticSearch"
flushTimeout="5000">
<target xsi:type="ElasticSearch"
uri="http://localhost:9200"
includeAllProperties ="true">
</target>
</target>
<rules>
<logger name="*" minlevel="Trace" writeTo="file" />
<logger name="*" minlevel="Trace" writeTo="ElasticSearch" />
</rules>
I'm trying to configure NLog for my C# application. I've got the logging working but it seems to have a mind of it's own in regards to whitespace. Here is my 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" >
<variable name="brief"
value="${longdate} | ${level} | ${logger} |: ${message}" />
<variable name="verbose"
value="${longdate} | ${machinename} | ${processid} | ${processname} | ${level} | ${logger} |: ${message}" />
<targets>
<target name="myLog" xsi:type="File" fileName="myLog.txt" layout="${verbose}" />
<target name="console" xsi:type="Console" layout="${brief}" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="myLog" />
<logger name="*" minlevel="Info" writeTo="console" />
</rules>
</nlog>
The log's output currently looks like this:
2016-05-19 12:08:00.0302|DEBUG|Namespace.ClassName|:Some log message here...
For some reason, NLog is getting rid of the spaces I defined in the target's layout attribute. What I would like the log entry to look like is:
2016-05-19 12:08:00.0302 | DEBUG | Namespace.ClassName |: Some log message here...
How do I get NLog to preserve the spaces in the layout attribute?
I've also tried to set the level to a fixed length with padding like this: ${padding:padding=5,fixedlength=true:${level:uppercase=true}} as mentioned in this post, but still no luck.
I discovered that NLog doesn't play nice when there is a # character in the path for the solution. Renamed the path and it started working again.
I have a unique problem with the NLog. I have a third-party assembly we use into our project. They have used the NLog into their project and referenced NLog configuration into their configuration which I don't have access to.
I initially had a problem even adding the NLog to a project since both version of dlls were different. I had to download the source code of NLog and change the assembly name since alias was not working for me (OR I didn't know how to use it.)
After giving my own assembly name, NLog started wotrking but.. It started logging third-party log information too with it. Looks like they were not careful enough when defining the logger and they just defined (*). Now my question is, how do I avoid their stuff from logging in to my file? I have also tried setting it to final = true.
Here is how my very simple configuration file looks like.
<?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">
<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
-->
<targets>
<!-- add your targets here -->
<!--
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
-->
<target name="errorLog" xsi:type="File"
fileName="${basedir}/logs/error/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}${onexception:${newline}EXCEPTION\: ${exception:format=ToString}}"
/>
<target name="generalLog" xsi:type="File"
fileName="C:/logs/${date:format=yyyy-MM-dd}.log"
layout="${longdate} ${uppercase:${level}} ${message}"/>
</targets>
<rules>
<!-- add your logging rules here -->
<logger name="Errors" writeTo="errorLog" minlevel="Warn"/>
<logger name="EBusiness.Model.*" writeTo="generalLog" levels="Trace,Debug,Info" final="true"/>
<!--
<logger name="*" minlevel="Trace" writeTo="f" />
-->
</rules>
</nlog>
If they are writing to the root logger, you should configure the root logger to not log to anywhere you care (maybe point it at a console logger) and your application can log to a specific logger which does write to your files.
Ugly, but should work.
For example:
Add this target:
<target name="console" xsi:type="Console" />
And Change the * rule to be:
<logger name="*" minlevel="Fatal " writeTo="console" />
Then, Add your own logger rule, say something like:
<logger name="MyNameSpace.*" minlevel="Trace" writeTo="logfile" final="true" />
Assuming you have a logfile target defined pointing at your file.
This sounds trivial, but I somehow cannot manage to do it. I have the below 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" autoReload="true" throwExceptions="true">
<variable name="logDirectory" value="${basedir}/App_Data/logs"/>
<targets>
<target name="file" xsi:type="AsyncWrapper">
<target xsi:type="File" name="f1" fileName="${logDirectory}\log1.txt" layout="${longdate} ${callsite} ${level} ${message} (File 1)"/>
</target>
<target xsi:type="File" name="fileGeneral" fileName="${logDirectory}\log_${shortdate}.txt" >
<layout xsi:type="Log4JXmlEventLayout"/>
</target>
<target xsi:type="File" name="fileRaven" fileName="${logDirectory}\raven_${shortdate}.txt" >
<layout xsi:type="Log4JXmlEventLayout"/>
</target>
</targets>
<rules>
<logger name="Raven.*" minlevel="Trace" writeTo="fileRaven"></logger>
<logger name="*" minlevel="Trace" writeTo="fileGeneral"></logger>
</rules>
</nlog>
This is ending up with Raven + ALL logs to 'log_[date].txt', and another copy of just RavenDB logs in 'raven_[date].txt'. How should this be done?
<logger name="Raven.*" minlevel="Trace" writeTo="fileRaven" final="true"></logger>
Where final="true" means that no more rules for Raven.* will be executed will do what you are asking (if I understood you correctly).
Unfortunately this is not possible.
The reason is that the loggers are evaluated from top to bottom, the first one matching will be used, and does below will not be evaluated.
In you case this means that when logging anything Raven related the first logger will be used and stops the flow.