How to log quartz and nhibernate in different log files using log4net - nhibernate

I use in my application nhibernate and qurtz and I would like the log4net to write the logs to different files. the nhibernate logs to "nhibernate.log" and the qurtz logs to "quartz.log".
How do I need to cinfigure the log4net config file to get this result??
Thanks, Avi.

You can configure which appender the nhibernate logger has to use:
<logger name="NHibernate">
<level value="ERROR" />
<appender-ref ref="NHibernateAppender"/>
</logger>
<logger name="NHibernate.SQL">
<level value="ERROR" />
<appender-ref ref="NHibernateAppender"/>
</logger>
Configure a different appender for your other loggers and you have sepparate log files.

Related

Running Gatling tests not showing testFile.log on IntelliJ

We have an issue where whenever our Gatling performance tests are run the .log file that should generate at the root of the folder is not there.
This is my whole logback file if anyone able to help please.
<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
<resetJUL>true</resetJUL>
</contextListener>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<!-- <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>INFO</level>
</filter> -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx</pattern>
<immediateFlush>true</immediateFlush>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>testFile.log</file>
<append>false</append>
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx</pattern>
</encoder>
</appender>
<!-- uncomment and set to DEBUG to log all failing HTTP requests -->
<!-- uncomment and set to TRACE to log all HTTP requests -->
<logger name="io.gatling.http.engine.response" level="TRACE" />
<root level="WARN">
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</root>
Thank you very much.
Update
It seems the issue may be with IntelliJ itself as noticed we can see the file when going directly to the finder.
Disabling custom plugins should help. Seems one of configuration was corrupted.
There's a good chance the file is simply not generated where you expect it. Try setting an absolute path instead to verify.

multi log4net instances using different configurations from the same config file

I am writing an application that will require 2 different loggers, each logging in a totally different way. When I create each instance of the log4net logger how can I get it to read from its own config section within the same app.config file. Is this possible as all I have seen so far is it taking the default
You can log two or more things independently without using separate config files.
LogManager.GetLogger("Log1")
LogManager.GetLogger("Log2")
Then in your config file you can create them like this
<logger name="Log1" additivity="false">
<level value="INFO" />
<appender-ref ref="LogFileAppender1" />
</logger>
<logger name="LOg2" additivity="false">
<level value="INFO" />
<appender-ref ref="LogFileAppender2" />
</logger>
By selecting additivity as false then they will log separately. You can then populate their appenders to write the info as needed.

Why does debug output show in WinDbg but not VS2010?

We have .NET 4 application that does some logging.
When the application is launched from Studio, there's no output in the Debug view.
When the application is launched from WinDbg, the logging is shown as expected.
I've read that there was a change in .NET 4 preventing the logging from showing up in both Studio and WinDbg, but it doesn't seem to show up in Studio at all now. Before the solution was upgraded, it did log as expected in VS2008.
Why is the Debug output showing up correctly when launched from WinDbg but not when launched from VS2010?
This was due to a misconfigured log4net.config file.
Added the <appender> block and <appender-ref> block to reference said appender.
<log4net>
...
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender" >
<layout type="log4net.Layout.PatternLayout">
<param name="Header" value="[Header]\r\n" />
<param name="Footer" value="[Footer]\r\n" />
<param name="ConversionPattern" value="%d [%t] %-5p %m%n" />
</layout>
</appender>
<root>
...
<appender-ref ref="ConsoleAppender" />
</root>
</log4net>

Changing Hibernate SQL logging level in Logback at runtime through JMX

I have configured Hibernate to use logback logging library. And created an appender that catches logging data from "org.hibernate.SQL" and "org.hibernate.type" loggers. By default, those are set to INFO level.
As the next step I try to change the level of those 2 loggers to DEBUG level using JMX interface of logback. But it does not work and log file contains no data. Only if I set the logging level to DEBUG in the configuration file and then restart the server it works.
Should I do anything additional in order to make Hibernate to start logging?
Here goes the appender/logger configuration:
<configuration debug="false" scan="true" scanPeriod="5 minutes">
<jmxConfigurator />
...
<property name="SQL_LOG_LEVEL" value="DEBUG" />
<appender name="SQL_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_DIRECTORY}/sql_${weblogic.Name}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>${ROTATION_DIRECTORY}/sql_${weblogic.Name}.%i.log.zip</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>5</maxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>50MB</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>${LOG_PATTERN}</pattern>
</encoder>
</appender>
<logger name="org.hibernate.SQL" level="${SQL_LOG_LEVEL}" additivity="false">
<appender-ref ref="SQL_LOG" />
</logger>
<logger name="org.hibernate.type" level="${SQL_LOG_LEVEL}" additivity="false">
<appender-ref ref="SQL_LOG" />
</logger>
...
</configuration>
EDIT: I have several applications (EAR) files deployed on the same container. All applications are using same logging configuration.
Problem appears to be in fact that I deploy several applications on one sever and, basically, each application's class loader has a copy of logback libraries. That's why several logging context are created, but because they all share the same name ("default"), basically, only one get registered to MBean server.
The solution could be either moving logback libraries higher in class loader hierarchy or use logger context separation as proposed by logback documentation.
I was not able to log any output from org.hibernate.SQL and friends until I set my log level to TRACE instead of DEBUG using logback over slf4j.

NHibernate - see SQL without all the other guff

So I'm using log4net to write log output to the trace. Show sql is specified in the configuration file. I seem to have to set the log output level to DEBUG to get the SQL output, but DEBUG also produces pages and pages of other guff I have to scroll past.
Can I get the SQL without the guff?
Thanks
David
You can add a logger for NHibernate.SQL in the log4net config block, like so:
<logger name="NHibernate.SQL" additivity="false">
<level value="DEBUG" />
<appender-ref ref="ConsoleAppender" />
</logger>
With the appender-config
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date - %message%newline"/>
</layout>
</appender>
(replace this with whatever you prefer, like rollingFileAppender)
Another option is using a tool like NHibernate Profiler.