log4net does not work in client pc - vb.net

I've problem with log4net where it doesn't work in client pc but in my development pc it can create and write to the log file.
My VSTO add-in is using log4net (installed log4net package using NuGet). So inside my add-in ribbon code, I've added the following code :
Ribbon.vb
<Assembly: log4net.Config.XmlConfigurator(Watch:=True)>
<Runtime.InteropServices.ComVisible(True)> _
Public Class WordRibbon
Implements Office.IRibbonExtensibility
Private ribbon As Office.IRibbonUI
Private Shared ReadOnly log As log4net.ILog = log4net.LogManager.GetLogger(
System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
......
app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false" />
</configSections>
<log4net>
<root>
<level value="ALL"/>
<appender-ref ref="RollingFileAppender"/>
</root>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="%envFolderPath{MyDocuments}\MyApp\AddInLog\WordAddin-log.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="5MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level %logger - %message%newline" />
</layout>
</appender>
</log4net>
When I ran MS Word in my development PC (either debug from Visual Studio 2013 OR directly ran MS Word), log4net will be able to create the logfile inside MyDocuments folder.
But when I ran the add-in inside a clean virtual machine, there's no log file created. THere's no error prompted. Am I missing something here?

I found out the problems in vsto 4.0 sp1 will cause a VSTO Addin to not find its config file link.
Difference is in my case, the add-in can be loaded properly and it's working. It just the log4net somehow didn't work.
Before:
In the add-in registry, the Manifest value will be something like
Manifest="C:\Program Files\MyApp\WordAddIn.vsto|vstolocal"
After:
In the blog, the writer suggested for below changes.
Manifest="file:///C:/Program Files/MyApp/WordAddIn.vsto|vstolocal"
And I think that's the reason why log4net can work in my development pc, because Visual Studio use the same URI format for the Manifest value.
But for my case, I tried below and it can also work.
Manifest="C:\Program Files\MyApp/WordAddIn.vsto|vstolocal"
I use this URI because in my app, during installation the addin registry value path will be created based on users selection. If I want to change it to file:///, this will involved a few different files (not just the add-ins), so for now this is my solutions.
I'm not sure if using this format can cause any problem.

Related

Log4Net on multiple nodes behind loadbalancer overwrite previous day rolling files

We are using the RollingFileAppender in a web-applicfation running behind a load-balaner on multiple nodes.
We noticed that logs of previous days often are very small, only a few lines, while the current log is large. It is not 100% consistent, about 1 in 5 previous logs apear to be a full log (using 2 nodes).
We figured that both nodes must be renaming log.log to the previous date with a minimal timespan between them. The last node to do so will actually overwrite the previous log with the new logfile created moments earlier by the first node.
This is our curated config:
<log4net>
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
<file value="\\shared-path\log.log" />
<datePattern value="yyyy-MM-dd.'txt'"/>
<staticLogFileName value="true"/>
<appendToFile value="true"/>
<rollingStyle value="Date"/>
<maxSizeRollBackups value="10"/>
<maximumFileSize value="20MB"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %message%newline"/>
</layout>
</appender>
<root>
<level value="ALL"/>
<appender-ref ref="RollingLogFileAppender"/>
</root>
</log4net>
Is there any simple way to prevent this from hapening?
The problem can be solved by setting <staticLogFileName value="false"/>.
In that case it will not rename log.log to the formatted archive name, but simply create a new file for the new log.
A disadvantage of this solution is that any Tail or monitoring tool will now have to check the directory for the newest file instead of just going for the static log.log.
Edit:
This is not a viable solution. We are missing chunks of logs, the time sometimes goes back 1 minute so log4net seems to be caching before flushing to the file...
See also this answer to the question Logging web services operations behind load balancer

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.

Pentaho CDE: Is there a way to debug the sql command being executed?

I'm wondering if there is a way to debug the sql command that SQL Query component executes at runtime?
I know placing a "console.log()" can debug components but SQL Query does not have an event to set the console up
Regards,
Erick
Shutdown Pentaho Server, goto YOURDRIVE:\pentaho\biserver-ce\tomcat\webapps\pentaho\WEB-INF\classes\
Open log4j.xml and uncomment this section:
<!--
<appender name="SQLLOG" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="../logs/mondrian_sql.log"/>
<param name="Append" value="false"/>
<param name="MaxFileSize" value="500KB"/>
<param name="MaxBackupIndex" value="1"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
</layout>
</appender>
<category name="mondrian.sql">
<priority value="DEBUG"/>
<appender-ref ref="SQLLOG"/>
</category>
-->
GOTO YOURDRIVE:\pentaho\biserver-ce\pentaho-solutions\system\mondrian
, open mondrian.properties, make sure below code is set to "true"
mondrian.rolap.generate.formatted.sql=true
Start the Pentaho server now, it will start making mysql log file in the "YOURDRIVE:\pentaho\biserver-ce\tomcat\logs\" folder when you execute the sql statements...
I ended up debugging thru SQL Server Management Studio

Log4net: The process cannot access the file because it is being used by another process

I have an asp.net website that is utilizing log4net. Due to several third party libraries (like NHibernate), there are several appenders across multiple threads. IIS is setup so there should be only one process. I have confirmed this by utilizing the process id in the filename.
Web.config Excerpt:
<appender name="AppAppender" type="log4net.Appender.RollingFileAppender">
<file type="log4net.Util.PatternString" value="Logs\App_[%processid]_.log" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<datePattern value="yyyy-MM-dd" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="false" />
<preserveLogFileNameExtension value="true" />
<threshold value="DEBUG" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value=" %date %-5level [%property{SessionId}] - %message%newline" />
</layout>
</appender>
When recycling the app pool in IIS I sometimes get these errors:
log4net:ERROR [RollingFileAppender] ErrorCode: GenericFailure. Unable to acquire lock on file App_[6844]_2014-12-18.log. Access to the path 'App_[6844]_2014-12-18.log' is denied.
My question, is are some of these error inevitable because its multi-threaded, or if configured properly should they never occur.
Additional Info:
I'm using log4net 1.2.13 (installed over nuget)
Frozen Mountain's WebSync (3.5.1.3), also note that this library directly references log4net 1.2.11, I used a bindingRedirect to 1.2.13
NHibernate version 3.1.0.400, it was the first version to not use log4net 1.2.10
**NHibernate can easily be upgraded if we think thats the problem. WebSync would be more difficult.

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>