[prev in list] [next in list] [prev in thread] [next in thread]
List: log4net-dev
Subject: log4net 1.2.13 Custom Header
From: Valentina Ichimov <vichimov () gmail ! com>
Date: 2015-09-10 9:33:23
Message-ID: CAHycF+vCiUXCsYJWfuxz45=rmWuV4VHDLph4SLDd10OFh0tX_w () mail ! gmail ! com
[Download RAW message or body]
Hello,
I tried to set for my RollingLogFile a custom header. Added only in the
head of file, once.
My application is installed in a web farm environment and I had issues
there. Multiple files were created(I used minimal lock as locking model).
Ex:
infoFile_2015_09_03.tsv
infoFile_2015_09_03.tsv2015_09_03.tsv
infoFile_2015_09_03.tsv2015_09_03.tsv2015_09_03.tsv
This is my code:
/// <summary>
/// Custom class for override the log4net Header Writing
/// </summary>
public class CustomHeaderLogFile : RollingFileAppender
{
protected override void WriteHeader()
{
if
(LockingModel.AcquireLock().Length == 0)
{
base.WriteHeader();
}
}
}
/// <summary>
/// Custom class for log4net Header Pattern
/// </summary>
public class CustomHeaderPatternLayout : PatternLayout
{
public override string Header
{
get
{
StringBuilder headerBuilder = new StringBuilder();
headerBuilder.AppendLine("Text \tSource \tTarget \tLocation \tResults
\tUserAgent \tUserIP");
return
headerBuilder.ToString();
}
}
}
And this is configuration:
<appender name="RollingStatsLogFileAppender" type=" CustomHeaderLogFile">
<file
type="log4net.Util.PatternString" value="C:\\Logs\\infoFile_"/>
<appendToFile value="true"/>
<lockingModel
type="log4net.Appender.FileAppender+MinimalLock"/>
<datePattern
value="yyyy'_'MM'_'dd'.tsv'"/>
<rollingStyle
value="Date"/>
<encoding value="utf-8"/>
<layout
type="CustomHeaderPatternLayout">
<conversionPattern value="%message%newline" />
</layout>
<staticLogFileName
value="false"/>
</appender>
There was something like different processes created a file for each.
When I enabled debugging I saw in the errors : log4net:ERROR
[CustomHeaderLogFile] ErrorCode: GenericFailure. Unable to acquire lock on
file C:\\Logs\\infoFile... The process cannot access the file .. because it
is being used by another process.
Can you help me with this issue?
I need to have a single file, with custom header, rolling by date, current
file should contain the current date.
Ex:
infoFile_2015_09_03.tsv
infoFile_2015_09_04.tsv
infoFile_2015_09_05.tsv
Thank you,
Vali
[Attachment #3 (text/html)]
<div dir="ltr">
<p class="MsoNormal">Hello,</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">I tried to set for my RollingLogFile a custom header. Added
only in the head of file, once.</p>
<p class="MsoNormal">My application is installed in a web farm environment and I
had issues there. Multiple files were created(I used minimal lock as locking
model).</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Ex:</p>
<p class="MsoNormal">infoFile_2015_09_03.tsv</p>
<p class="MsoNormal">infoFile_2015_09_03.tsv2015_09_03.tsv</p>
<p class="MsoNormal">infoFile_2015_09_03.tsv2015_09_03.tsv2015_09_03.tsv</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">This is my code:</p>
<p class="MsoNormal">
/// <summary></p>
<p class="MsoNormal">
/// Custom class for override the log4net Header Writing</p>
<p class="MsoNormal">
/// </summary></p>
<p class="MsoNormal">
</p>
<p class="MsoNormal">
public class CustomHeaderLogFile : RollingFileAppender</p>
<p class="MsoNormal">
{</p>
<p class="MsoNormal">
protected override void WriteHeader()</p>
<p class="MsoNormal">
{</p>
<p class="MsoNormal">
if (LockingModel.AcquireLock().Length == 0)</p>
<p class="MsoNormal">
{</p>
<p class="MsoNormal">
base.WriteHeader();</p>
<p class="MsoNormal">
}</p>
<p class="MsoNormal">
}</p>
<p class="MsoNormal">
}</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">
/// <summary></p>
<p class="MsoNormal">
/// Custom class for log4net Header Pattern</p>
<p class="MsoNormal">
/// </summary></p>
<p class="MsoNormal">
public class CustomHeaderPatternLayout : PatternLayout</p>
<p class="MsoNormal">
{</p>
<p class="MsoNormal">
public override string Header</p>
<p class="MsoNormal">
{</p>
<p class="MsoNormal">
get</p>
<p class="MsoNormal">
{</p>
<p class="MsoNormal">
StringBuilder headerBuilder = new StringBuilder();</p>
<p class="MsoNormal">
headerBuilder.AppendLine("Text \tSource \tTarget \tLocation \tResults
\tUserAgent \tUserIP");
</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">
return headerBuilder.ToString();</p>
<p class="MsoNormal">
}</p>
<p class="MsoNormal">
}</p>
<p class="MsoNormal">
}</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">And this is configuration:</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"><appender name="RollingStatsLogFileAppender"
type=" CustomHeaderLogFile"></p>
<p class="MsoNormal">
<file type="log4net.Util.PatternString"
value="C:\\Logs\\infoFile_"/></p>
<p class="MsoNormal">
<appendToFile value="true"/></p>
<p class="MsoNormal">
<lockingModel
type="log4net.Appender.FileAppender+MinimalLock"/></p>
<p class="MsoNormal">
<datePattern value="yyyy'_'MM'_'dd'.tsv'"/></p>
<p class="MsoNormal">
<rollingStyle
value="Date"/>
</p>
<p class="MsoNormal">
<encoding value="utf-8"/></p>
<p class="MsoNormal">
<layout type="CustomHeaderPatternLayout"></p>
<p class="MsoNormal">
<conversionPattern value="%message%newline" /></p>
<p class="MsoNormal">
</layout></p>
<p class="MsoNormal">
<staticLogFileName
value="false"/>
</p>
<p class="MsoNormal">
</appender></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">There was something like different processes created a file
for each.</p>
<p class="MsoNormal">When I enabled debugging I saw in the errors : log4net:ERROR
[CustomHeaderLogFile] ErrorCode: GenericFailure. Unable to acquire lock on file
C:\\Logs\\infoFile... The process cannot access the file .. because it is being
used by another process.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Can you help me with this issue?</p>
<p class="MsoNormal">I need to have a single file, with custom header, rolling by
date, current file should contain the current date.</p>
<p class="MsoNormal"><span style="mso-ansi-language:FR" lang="FR">Ex: </span></p>
<p class="MsoNormal"><span style="mso-ansi-language:FR" lang="FR">infoFile_2015_09_03.tsv</span></p>
<p class="MsoNormal"><span style="mso-ansi-language:FR" lang="FR">infoFile_2015_09_04.tsv</span></p>
<p class="MsoNormal"><span style="mso-ansi-language:FR" lang="FR">infoFile_2015_09_05.tsv</span></p>
<p class="MsoNormal"><span style="mso-ansi-language:FR" lang="FR"> </span></p>
<p class="MsoNormal"><span style="mso-ansi-language:FR" lang="FR"> </span></p>
<p class="MsoNormal">Thank you,</p>
<p class="MsoNormal">Vali</p>
</div>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic