${date}接受与相同的格式
DateTime.ToString。不幸的是,.NET没有ww或weeknumber格式(请参阅自定义日期和时间格式字符串 -.NET |
Microsoft Docs)
论坛上的链接谈论的是Joda Time,它是Java而不是.NET的库。
// This presumes that weeks start with Monday.// Week 1 is the 1st week of the year with a Thursday in it.public static int GetIso8601WeekOfYear(DateTime time){ // Seriously cheat. If its Monday, Tuesday or Wednesday, then it'll // be the same week# as whatever Thursday, Friday or Saturday are, // and we always get those right DayOfWeek day = CultureInfo.InvariantCulture.Calendar.GetDayOfWeek(time); if (day >= DayOfWeek.Monday && day <= DayOfWeek.Wednesday) { time = time.AddDays(3); } // Return the week of our adjusted day return CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(time, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);}
创建一个渲染2019.25等的布局渲染器(请参阅NLog文档-
如何编写自定义布局渲染器)
using NLog.LayoutRenderers;using NLog;...// register ${myDateTime}. Register a soon as possible (e.g main(), app_start etc)LayoutRenderer.Register("myDateTime", logEventInfo => logEventInfo.TimeStamp.Year +"." + GetIso8601WeekOfYear(logEventInfo.TimeStamp));
现在这应该工作:
index = "logstash-${myDateTime}"
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)