I'm using the latest 5.x ReSharper plugin with NUnit 2.5.10. When using Log4Net to log some events for testing purposes the results show up in the ReSharper test window, but do not show up when using NUnit's console unit runner (run as part of our build processes). I've tried giving NUnit a .config file in the same location as the .nunit configuration file with the LogLevelThreshold set to DEBUG, but it still won't log the actual test information to either the output file or the text window in NUnit's GUI. I'm a bit stumped at this point, is there a way to get the two in sync in what's being displayed by test output? Thanks!
Configs in question:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="NUnit">
<section name="TestCaseBuilder" type="System.Configuration.NameValueSectionHandler"/>
<section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
</sectionGroup>
</configSections>
<NUnit>
<TestRunner>
<add key="DefaultLogThreshold" value="DEBUG" />
</TestRunner>
</NUnit>
</configuration>
And other config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net debug="false">
<appender name="console" type="log4net.Appender.ConsoleAppender, log4net">
<layout type="log4net.Layout.PatternLayout, log4net">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
<appender name="DebugAppender" type="log4net.Appender.DebugAppender, log4net">
<layout type="log4net.Layout.PatternLayout, log4net">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="console" />
<!--<appender-ref ref="DebugAppender" />-->
</root>
<logger name="NHibernate">
<level value="INFO" />
</logger>
<logger name="NHibernate.SQL">
<level value="DEBUG" />
</logger>
</log4net>
</configuration>
Thanks in advance for any help.
Related
I have problem when export to executable jar.
I'm using maven and slf4j with log4j
My pom.xml
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.2</version>
<scope>runtime</scope>
</dependency>
I added a log4j.xml in /src/java/main (is the same that in generated target folder):
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="FILE" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="/media/dlm/log/dlm.log" />
<param name="Threshold" value="INFO" />
<param name="Append" value="false" />
<param name="MaxFileSize" value="10MB" />
<param name="MaxBackupIndex" value="1" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}:%L] %m %n" />
</layout>
</appender>
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<param name="Threshold" value="INFO" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{ABSOLUTE} %-5p [%c{1}:%L] %m %n" />
</layout>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="FILE" />
</root>
</log4j:configuration>
But when I export from eclipse the log4j.xml is changed for the next one:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="FILE" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="/tmp/dlm/log4j.log" />
<param name="Threshold" value="INFO" />
<param name="Append" value="false" />
<param name="MaxFileSize" value="1MB" />
<param name="MaxBackupIndex" value="1" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p %X{service} %X{user} [%c] %m%n" />
</layout>
</appender>
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<param name="Threshold" value="ERROR" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{ABSOLUTE} %-5p %X{service} %X{user} [%c{1}] %m%n" />
</layout>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="CONSOLE" />
</root>
</log4j:configuration>
I tried using log4j.properties file as appear here, but nothing.
Thanks in advance your answers.
Thanks to Peter I understood that when run an aplicacition with eclipse I was using eclipse options and not maven itself to build my app. That was the reason log4j.xml probably change. The next solution not resolve why it happens, but resolve the problem and give me a correct way to build my app using 100% maven.
I just need to add some new fields to my pom.xml to make things that eclipse options probably add automatically.
1.-Include xml files:
<build>
...
<!-- RECURSOS -->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.fxml</include>
<include>log4j.xml</include>
</includes>
</resource>
</resources>
...
</build>
2.- Executable jar (I have 3 different main classes in same project):
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>${class.main}</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
3.- Add profiles to select main class:
<profiles>
<!-- DLM ANALOG -->
<profile>
<id>dlmdesktopanalog</id>
<properties>
<class.main>cl.icpdas.dlm.desktop.fx.main.analog.DataLoggerAnalogManager</class.main>
</properties>
</profile>
<!-- DLM DIGITAL -->
<profile>
<id>dlmdesktopdigital</id>
<properties>
<class.main>cl.icpdas.dlm.desktop.fx.main.digital.DataLoggerDigitalManager</class.main>
</properties>
</profile>
<!-- DLM EXTRACTOR -->
<profile>
<id>dlmdesktopextractor</id>
<properties>
<class.main>cl.icpdas.dlm.desktop.fx.main.extractor.DataLoggerExtractorManager</class.main>
</properties>
</profile>
</profiles>
Finally, I used the next goals make my executable jar.
mvn clean package assembly:single -e -P dlmdesktopanalog
Anyway, if someone knows where eclipse set log4j.xml and other options when make a exejutable jar or what is reasson why it changes log4j.xml the answers are wellcome as comment.
I have downloaded the newest version of Quartz.Net and try to configure it with common.logging and log4net dlls by using below configuration (based on this example)
<configSections>
<section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=2.1.2.400,Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4" />
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging, Version=2.1.2.0, Culture=neutral, PublicKeyToken=af08829b84f0328e" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
<arg key="configType" value="INLINE" />
</factoryAdapter>
</logging>
<log4net>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="MyQuartzLog.txt" />
<param name="AppendToFile" value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%-5p%d{yyyy-MM-dd hh:mm:ss} – %m%n" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
</root>
</log4net>
<quartz>
<add key="quartz.scheduler.instanceName" value="QuartzTestLog4Net" />
<add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" />
<add key="quartz.threadPool.threadCount" value="10" />
<add key="quartz.threadPool.threadPriority" value="2" />
<add key="quartz.jobStore.misfireThreshold" value="60000" />
<add key="quartz.jobStore.type" value="Quartz.Simpl.RAMJobStore, Quartz" />
</quartz>
It does not work.
<section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=2.1.2.400,Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4" />
results in component loading error. I used sn.exe to check the publickeytoken. The keytoken is correct.
Removing the quartz sction can make the application run. But the log object has NoOpLogger information - {Common.Logging.Simple.NoOpLogger}.
My project refers to Common.Logging version 2.1.2.0; Common.Logging.Log4Net version 2.0.0.0; and log4net version 1.2.10.0. Are they right versions? If not, what are the right ones.
Thanks,
You should check the sample server that comes with Quartz.NET distribution.
https://github.com/quartznet/quartznet/tree/master/server/Quartz.Server
App.config:
It's type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"
NameValueSectionHandler is BCL type, not Quartz.NET's
You can probably leave out the version and public key
Package.config
You might have wrong packages. packages.config in sample contains working combination when using Log4Net 1.2.11
In a C# 2008 application, I want to write the NLog error log files out so that the files have a date on them. In the example listed below, you can see that I have 3 log files. Can you tell me how place a month-day-year format on these files?
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
</sectionGroup>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
</configSections>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="logfile" xsi:type="File" fileName="C:\Logs\NlogOutput.log" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="logfile" />
</rules>
</nlog>
Use something like this for your fileName parameter:
fileName="${basedir}/${shortdate}.log"
Generally speaking, you can use most NLog LayoutRenderers to help compose your filename.
I want to deploy my web application on JBOSS6. The applicaation itself works, but the logging doens't. I use log4j and have added a jboss-deployment-structure.xml to my war. The contents are
<jboss-deployment-structure>
<deployment>
<!-- Exclusions allow you to prevent the server from automatically adding some dependencies -->
<exclusions>
<module name="org.apache.log4j" />
<module name="org.jboss.logging" />
</exclusions>
</deployment>
In my log4j.xml I have
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "dtd/log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="LogAppender" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="C:\\logs\\web.log"/>
<param name="MaxFileSize" value="10000KB"/>
<param name="MaxBackupIndex" value="10"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%x %-5p [%d{yyyyMMdd HH:mm:ss}] - %c:%L - %m%n"/>
</layout>
</appender>
<logger name="be.sofico.web">
<level value="debug" />
<appender-ref ref="LogAppender" />
</logger>
This all works fine on tomcat and websphere (when I set classloading parent last)
How can I get it to work on JBOSS 6?
I solved my problem doing the following:
put jboss-deployment-structure.xml inside web\META-INF with the following in the file
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.apache.log4j" />
<module name="org.apache.commons.logging" />
</exclusions>
</deployment>
</jboss-deployment-structure>
And add this to the startup of the server: -Dorg.jboss.as.logging.per-deployment=false
to set my log4j in the classpath correctly i did 2 things :
1) I set the name of the log4j to use like this
-Dlog4j.configuration=fox-log4j.xml
this one has to be in the CLASSPATH
2) I call the logging manager explicitly otherwise the jboss log4j wont work
this gives in my run.conf :
#parameter used by the JVM and call later in the log4j.xml
LOG_FOLDER=$DIRNAME/../server/default/log
#jvm options
JAVA_OPTS="-Xms256m -Xmx4096m -XX:MaxPermSize=1024m -Dlog4j.configuration=fox-log4j.xml \
-Dfile.encoding=UTF-8 -Dfile.io.encoding=UTF-8 -DjavaEncoding=UTF-8 -Djboss.platform.mbeanserver \
-Djavax.management.builder.initial=org.jboss.system.server.jmx.MBeanServerBuilderImpl \
-Djava.util.logging.manager=org.jboss.logmanager.LogManager \
-Dorg.jboss.logging.Logger.pluginClass=org.jboss.logging.logmanager.LoggerPluginImpl \
-DLOG_FOLDER=$LOG_FOLDER"
now a piece of my log4j :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="FOX_LOG" class="org.apache.log4j.RollingFileAppender">
<param name="Threshold" value="DEBUG"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="25MB"/>
<param name="MaxBackupIndex" value="5"/>
<param name="File" value="${LOG_FOLDER}/fox.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} %-15x %t %-5p %-50.50c{1} - %m%n"/>
</layout>
</appender>
<category name="com.mycompany" additivity="true">
<priority value="DEBUG"/>
<appender-ref ref="FOX_LOG"/>
</category>
<root>
<priority value="INFO"/>
<appender-ref ref="FILE"/>
</root>
</log4j:configuration>
hope this could help.
regards
It means it is not loading your log4j.xml. Something wrong with the xml file location or issue with the class loader finding this log4j.xml.
I am trying to run my unit tests with nHibernate 3 and fluentnHibernate, To do this I need to setup a assembly binding redirect so fluentnHibernate will work with the new version of nHibernate. I have tried to update my test project's app.config however the testdriven.net runner and the nunit gui runner don't seem to read these settings.
below is my test.dll's app.config.
<configuration>
<configSections>
<!-- Others sections -->
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<connectionStrings>
<add name="Test" connectionString="Data Source=SQL2008, 1080;Initial Catalog=TestCOM;Integrated Security=True"/>
</connectionStrings>
<log4net>
<appender name="GeneralLog" type="log4net.Appender.RollingFileAppender">
<file value="Logs.txt"/>
<appendToFile value="true"/>
<maximumFileSize value="100KB"/>
<rollingStyle value="Size"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%d{HH:mm:ss} [%t] %-5p %c - %m%n"/>
</layout>
</appender>
<logger name="NHibernate.SQL" additivity="false">
<level value="DEBUG"/>
<appender-ref ref="GeneralLog"/>
</logger>
</log4net>
<startup useLegacyV2RuntimeActivationPolicy="true">
<requiredRuntime version="v4.0.30319" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly
partialName="System.Data.SqlServerCe"
fullName="System.Data.SqlServerCe,
Version=3.5.1.0, Culture=neutral,
PublicKeyToken=89845dcd8080cc91"/>
<dependentAssembly>
<assemblyIdentity name="NHibernate"
publicKeyToken="AA95F207798DFDB4"
culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-3.0.0.1001"
newVersion="3.0.0.1001"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
I am getting the following error:
TestCase 'FieldGuideTests.Service.SchemaFacts.Can_Build_SQL_Schema'
failed: System.IO.FileLoadException : Could not load file or assembly 'NHibernate, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at FieldGuideService.SessionFactoryManagers.SQL_SessionFactoryManager.CreateSessionFactory()