NLog use Persian Calendar Date format

I am interested in using NLog in my C# project and found it great, but
In my country Clients works with "Persian Calendar".
As you know Microsoft developed a library to support named "C# Persian Calendar class".
I need Persian calendar date format in two places
1-Message Time stamp
2-Date based File Name
How to force NLog to use " C# Persian Calendar class" in above usages?
Thanks

Jon Skeet
people
quotationmark

There are two difficulties with this:

  • You'd need to work out how the formatting is performed in both of these cases, and see how you can customize it, e.g. by specifying a different culture or a formatting delegate
  • The Persian calendar isn't currently an optional calendar for any culture, so using DateTime.ToString won't work anyway :(

You'll definitely need to look into the source code (or at least documentation) for NLog to find out whether there's a way of configuring the formatting. Once you've worked out how to get your own code to be executed there - e.g. by writing your own subclass, potentially - you'll need to work out how to do the actualy formatting.

You could do this using the BCL, calling into PersianCalendar and doing simple numeric formatting. Or you could use my Noda Time library, which also has Persian calendar support (as of Noda Time 1.3). You'd want something like:

var gregorian = new LocalDate(2014, 11, 6); // Or whatever
var persian = gregorian.WithCalendar(CalendarSystem.GetPersianCalendar());
var text = persian.ToString("yyyy-MM-dd"); // Or create a LocalDatePattern

people

See more on this question at Stackoverflow