views:

131

answers:

3

I used RollingFileAppender. And I want add a blank line to the log when my program launches. How to do that? Thanks.

Edit: OK, thanks for you all. Sorry for the confused question I asked. Let me make some explanation. I config the log4net as follows:

<log4net>
  <appender name="MyFileAppender" type="log4net.Appender.RollingFileAppender">
    <param name="File" value="ClientLog.log" />
    <param name="AppendToFile" value="true" />
    <layout type="log4net.Layout.PatternLayout">
      <param name="ConversionPattern" value="%date{yyyy/MM/dd HH:mm:ss},%5p,%m%n" />
    </layout>
  </appender>

  <logger name="GlobalUse" >
    <level value="Info"/>
    <appender-ref ref="MyFileAppender" />
  </logger>

</log4net>

and the log will be:

2010/03/27 13:55:27, INFO, Program start.
2010/03/27 13:55:29, INFO, Program end.
2010/03/27 13:56:30, INFO, Program start.
2010/03/27 13:56:32, INFO, Program end.

What i hope is make the log looks like this:

2010/03/27 13:55:27, INFO, Program start.
2010/03/27 13:55:29, INFO, Program end.

2010/03/27 13:56:30, INFO, Program start.
2010/03/27 13:56:32, INFO, Program end.

2010/03/27 13:57:30, INFO, Program start.
...

Any idea? Thanks.

A: 

Uh...

Log.Debug("Starting...");
jvenema
+3  A: 

Log.Debug(Environment.Newline);

Russell Steen
Thanks for you answer. I edited the question. That maybe more clear.Your solution can add a newline indeed. But the last logline would be little strange.
Jollian
+2  A: 

You would need a special appender. Here you have a configuration example


<log4net>
  ...
  <appender name="MyRollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
    <file value="C:\temp\mylog.log" />
    <appendToFile value="true" />
    <rollingStyle value="Date" />
    <datePattern value="yyyyMMdd" />
    <staticLogFileName value="true" />
    <maximumFileSize value="2MB" />
    <maxSizeRollBackups value="20" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%message%newline" />
    </layout>
  </appender>

  <logger name="MyLogger">
    <level value="Info" />
    <appender-ref ref="MyRollingLogFileAppender" />
  </logger>  
  ...
</log4net>

This configuration allows the insert of a WHITE LINE, COMPLETELY WHITE (<conversionPattern value="%message%newline" />)

And the code to log would be

LogManager.GetLogger("MyLogger").Info("");

A last comment: this allows you to do what I think you want but I wouldn't do it in my own development :-) if I misunderstood your question please let me know

EDIT1 This appedender / logger is ADDED to your existing configuration. It would be ONLY used to generate the white line you need. For the rest of the logging you would use your previously existing logger / appender,

Claudio Redi
Thanks for you answer. But that will make insert a newline everytime when i log. I made some explanation to my question. You would have a look at that, if you still have interest in the question.
Jollian
Good solution. Thanks a lot.
Jollian