I'm using Log4Net (1.2.10.0) for logging in my application.
It's working fine - till I run it on Vista SP2 under Guest user. The log file does not contains a newline characters - all log is a single line.
This is not happen when I run the application as regular or admin user.
Only in case of built-in guest account.
Any ideas?
The configuration is as following:
<appender name="clientRollingFile" type="log4net.Appender.RollingFileAppender">
<file value="C:\users\public\client.log" />
<appendToFile value="true" />
<maximumFileSize value="100KB" />
<maxSizeRollBackups value="5" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %-5level %logger [%type{1}] [%ndc] - %message%newline" />
</layout>
</appender>
Thank
Try the following layout, which includes a newline in code and not in configuration. See if the problem still occurs.
<layout type="log4net.Layout.SimpleLayout">
This won't "fix" anything, but it may help us narrow down the issue.
Related
In my NUnit 2.6 tests I used to see log4net log messages in the output window of Visual Studio, in the Tests section. Since I switched to NUnit 3.2, they are no longer displayed, which is very inconvenient. I tried searching and the best "solution" I came up with was to dump everything into debug strings, which can be viewed either via DebugView utility from SysInternals or when I actually debug a test - then the messages are shown in Debug section. However, I would really like to see my log lines in the Visual Studio even when not debugging. Any ideas? Visual Studio 2015. This is my current log4net config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
</configSections>
<log4net>
<appender name="OutputDebugStringAppender" type="log4net.Appender.OutputDebugStringAppender" >
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<appender name="DebugAppender" type="log4net.Appender.DebugAppender" >
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="OutputDebugStringAppender" />
<appender-ref ref="DebugAppender" />
</root>
</log4net>
</configuration>
NUnit V2 captured log4net output and translated it into an NUnit event. For 3.0, we decided this was out of scope for NUnit and left it to log4net to display things. When running under the NUnit console runner, this works fine but it turns out to be a bit of a limitation under the VS adapter.
I think it would be reasonable for us to supply either an appender or an engine extension you could use to get log4net output into the form of an NUnit output event. It's a matter of someone volunteering to write it. If you think this is important, you might file an issue on github.
For NUnit v3 you can do that with this line of code:
Console.SetOut(TestContext.Progress);
Log4Net configured to use ConsoleAppender.
For me the solution was to set the ConsoleAppender's target property to "Console.Out":
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender, log4net">
<target value="Console.Out"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date{dd MMM yyyy HH:mm:ss} %level [%thread] %method - %message%n" />
</layout>
</appender>
Did not need to set out to TestContext.Progress.
This is with NUnit 3.11 and the R# testrunner.
PS. Noticed we're using different appenders. I'll leave this in here anyway since it's came up in my main SERP. :)
I'm trying to get log4net to log via udp to chainsaw but its not working on windows 7. My config files are as follows:
<log4net debug="true">
<appender name="trace" type="log4net.Appender.TraceAppender, log4net">
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
</layout>
</appender>
<appender name="UdpAppender" type="log4net.Appender.UdpAppender">
<remoteAddress value="127.0.0.1" />
<remotePort value="8085" />
<layout type="log4net.Layout.XmlLayoutSchemaLog4j">
<locationInfo value="true" />
</layout>
</appender>
<root>
<level value="TRACE" />
<appender-ref ref="trace" />
<appender-ref ref="UdpAppender" />
</root>
my chainsaw config file looks like this:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">
<plugin name="UDPReceiver" class="org.apache.log4j.net.UDPReceiver">
<param name="Port" value="8085" />
</plugin>
</log4j:configuration>
All of this is per the documentation found in: http://logging.apache.org/log4net/release/howto/chainsaw.html
Yet none of the logs show up.
Figured it out. Looks like log4net has issues with ipv6 and windows 7. To get around these issues you need to add an entry into your host file that looks like this:
127.0.0.2 localhosttwo
then your UpdAppender needs to reference that DNS entry as so:
<remoteAddress value="localhosttwo" />
127.0.0.2 is the ipv6 address for your localmachine and you need an explcit dns entry or else log4net will throw an error if you try and use the numerical address in the config file.
Make sure to flush your dns after you change the hostfile
I've been working on a web application using Visual Studio 2010 on a Windows 7 OS.
I used Log4Net for logging on the Event Viewer and that worked out great, meaning that everything is being correctly logged on my Windows 7 Event Viewer.
After installing this same project on a Windows Server 2003 Machine, I've noticed that nothing get's logged...
I already added the ASPNET on the Administrators group of the Windows Server 2003 machine but still the problem persists...
On the AssemblyInfo.cs file I added:
[assembly: log4net.Config.XmlConfigurator()]
On Web.config file I added:
...
...
-->
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
<param name="LogName" value="MyLog" />
<param name="ApplicationName" value="MyApplication" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<!-- Setup the root category, add the appenders and set the default level -->
<root>
<level value="INFO" />
<appender-ref ref="ConsoleAppender" />
</root>
<!-- ApplicationKit category - the presentation UI -->
<logger name="MyLogger">
<level value="INFO" />
<appender-ref ref="FileAppender" />
<appender-ref ref="EventLogAppender" />
</logger>
And finally on the code behind:
...
log4net.Config.XmlConfigurator.Configure();
Ilog log = LogManager.GetLogger("MyLogger");
...
I already created the MyLog key value on:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog
But still, nothing gets logged there.
I'm 100% percent sure this works perfectly on Windows 7.
Do I need to make some oyher special configuration on Windows Server 2003?
Thanks in advance
Well...
As it turned out I also had to give the NETWORK SERVICE full permissions to the following key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog
Voila
I'm trying to add log4net logging to a web application I'm writing. I've got this in a web service method:
log4net.Config.XmlConfigurator.Configure();
log4net.ILog log = log4net.LogManager.GetLogger(typeof(Methods));
log.Info("Some information");
And this in the web.config file:
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Windows" />
<identity impersonate="true"/>
</system.web>
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.RollFileAppender">
<file value="log.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="1MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.SimpleLayout" />
</appender>
<root>
<level value="ALL" />
<appender-ref ref="LogFileAppender" />
</root>
</log4net>
I was expecting the log file to appear in the bin\ directory when I debug it through Visual Studio 2010, but nothing is written there. The method runs successfully without any exceptions, but I can't find the log file. Any ideas as to where it should appear?
Edit - Some extra info:
According to the notification area icon, the ASP.Net Development Server is running in:
C:\Users\jpope\Documents\Visual Studio 2010\Projects\WebApplication1\WebApplication1\
The permissions on this directory and the \bin\ sub-directory both give SYSTEM, me and Administrators full control, and no one else any access. The log file is not in the directory shown above or the \bin\ sub-directory.
If you're willing to wade into some low-level stuff, it might be interesting to see what Process Monitor thinks the web server process is trying to write to. At least it would be more fun than wading through the log4net documentation.
Maybe you should set the asp.net user has the write right for you web directory.
This turned out to be a configuration problem. Switching to a FileAppender instead of a RollFileAppender works fine. Now I need to find out what's wrong with the RollFileAppender configuration...
Edit: It's a RollingFileAppender, not a RollFileAppender.
I'm running Visual Studio 2008 - and have a problem with log4net logging (v1.2.10).
I have a small console test program with a single log statement.
I have log4net configured for RollingLogFileAppender and ConsoleAppender.
When I run the compiled exe from the command line, I see the correct creation of the log file in my runtime directory. The log file is created (or appended to, when it exists), but the only output is the [Header] and [Footer] as configured. There is no output to console.
However, when I run under the debugger, the log message appears both in the log file and on the console. Following is my log4net configuration:
<log4net>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout" value="%date [%thread] %-5level %logger - %message%newline" />
</appender>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="quicktest-log-" />
<appendToFile value="true" />
<immediateFlush value="true" />
<datepattern value="yyyy-MM-dd" />
<maxSizeRollBackups value="100" />
<maximumFileSize value="1048576" />
<rollingStyle value="Composite" />
<staticLogFileName value="false" />
<layout type="log4net.Layout.PatternLayout">
<header value="[Begin Quicktest program log]
" />
<footer value="[End Quicktest program log]
" />
<conversionPattern value="%date{HH:mm:ss} [%thread] %-5level %logger: %message%newline" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="ConsoleAppender" />
<appender-ref ref="RollingLogFileAppender" />
</root>
</log4net>
This theory could be a stretch, but have you ensured that the app.config has been copied to the folder where your executable is? App.config must be copied to where the output executable is, and you also must rename it to <executablename>.config, so if your executable is MyProgram.exe, config must be in MyProgram.exe.config.
It is working now, but the mystery remains. Apparently a bellyful of Chinese buffet is the only solution to a problem like this, for once I had one, the problem went away.
My test program was a single file with
class Test
{
static void Main (string[] args)
{
.
. // some logging attempted here.
.
}
}
When I had the problem originally, I was doing the logging within Main(). Afterwards, I created a method on the class Test, instantiated class Test in Main, and moved the logging to the method. This removed the problem:
class Test
{
static void Main (string[] args)
{
var p = new Test();
p.Go ();
}
public void Go ()
{
. // some logging here.
}
}
This is still inconclusive. I moved it back the way it was originally and it began working. So, I must conclude that the answer to this conundrum is: Do not attempt first-time log4net test programs without a bellyful of Chinese food.
I had the same issue, and I was doing clickonce deployment.
I found that i need to add log4net.xml in Project properties > Publish > ApplicationFiles and make this log4net.xml as datafile.