[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">               
/// &lt;summary&gt;</p>

<p class="MsoNormal">               
/// Custom class for override the log4net Header Writing</p>

<p class="MsoNormal">               
/// &lt;/summary&gt;</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">               
/// &lt;summary&gt;</p>

<p class="MsoNormal">               
/// Custom class for log4net Header Pattern</p>

<p class="MsoNormal">               
/// &lt;/summary&gt;</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(&quot;Text \tSource \tTarget \tLocation \tResults
\tUserAgent \tUserIP&quot;);                         
</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">&lt;appender name=&quot;RollingStatsLogFileAppender&quot;
type=&quot; CustomHeaderLogFile&quot;&gt;</p>

<p class="MsoNormal">                                               
&lt;file type=&quot;log4net.Util.PatternString&quot;
value=&quot;C:\\Logs\\infoFile_&quot;/&gt;</p>

<p class="MsoNormal">                                               
&lt;appendToFile value=&quot;true&quot;/&gt;</p>

<p class="MsoNormal">                                               
&lt;lockingModel
type=&quot;log4net.Appender.FileAppender+MinimalLock&quot;/&gt;</p>

<p class="MsoNormal">                                               
&lt;datePattern value=&quot;yyyy&#39;_&#39;MM&#39;_&#39;dd&#39;.tsv&#39;&quot;/&gt;</p>

<p class="MsoNormal">                                               
&lt;rollingStyle
value=&quot;Date&quot;/&gt;                                     
</p>

<p class="MsoNormal">                                               
&lt;encoding value=&quot;utf-8&quot;/&gt;</p>

<p class="MsoNormal">                                               
&lt;layout type=&quot;CustomHeaderPatternLayout&quot;&gt;</p>

<p class="MsoNormal">                                                               
&lt;conversionPattern value=&quot;%message%newline&quot; /&gt;</p>

<p class="MsoNormal">                                               
&lt;/layout&gt;</p>

<p class="MsoNormal">                                               
&lt;staticLogFileName
value=&quot;false&quot;/&gt;                                      
</p>

<p class="MsoNormal">                               
&lt;/appender&gt;</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