开发者

A need for DayOfYear in Log4Net

In log4j you could use a date pattern of %d{DDD:HHmmss} where the DDD would be the Day Of Year. I need to do an equivalent type of pattern in our C# app and I cannot figure out how to get this working.开发者_开发问答 DataTime ToString doesn't seem to have a formatter for Day Of Year but it does have a property for it call DateTime.DayOfYear. Anyone know how to get my date pattern set with day of year in log4net? Any advice is much appreciated.

To be clearer, I am really trying to find a log4net pattern to use in my App.Config that will format the date part of the output in the logfile. To wit in my App.Config within my appender I have:

<layout type="log4net.Layout.PatternLayout">
  <conversionPattern value="%d{MMdd-HHmmss} %-5.5p %c{1}:%L - %m%n" />
</layout>

This outputs something like:

0319-175824 INFO  Program:33 - Entering Main Method

Would like it to output:

078-175824 INFO  Program:33 - Entering Main Method


You could create your own implementation of DateTimeDateFormatter that outputs the format you require.

FormatDate looks like the method you would want to override.

Alternatively, you could inject a property containing DateTime.DayOfYear and reference it using the property syntax %property{doy}

log4net.GlobalContext.Properties["doy"] = DateTime.DayOfYear;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜