WHAT'S NEW?
Loading...

NuGet Package of the Week: MarkdownLog makes log files much prettier

While I"m not 100% gaga over Markdown as I know many of you are, I definitely appreciate it"s usefulness and it"s clarity. Some folks would say I shouldn"t rest until every binary document on my hard drive has been converted to Markdown. I say, nay nay. That said, I totally dig MarkdownPad and you should use it every day. It"s lovely.

If you don"t want to install anything, check out http://dillinger.io and quickly edit some Markdown in the browser.

image

But, I digress.

Note: Be sure to check out all the NuGet packages of the week! There"s more!

The general idea behind Markdown is that HTML is way too complex for 90% of what you need, so rather than

    and
  • and all that, why not just express bullets with asterisks? We can all get behind that. There are many other simple Markdown syntaxes that you can learn in a few minutes. Once you"ve created some Markdown, you can easily generate PDFs, HTML, Word Documents, whatever you like.

    Recently I stumbled upon Stuart Wheelwright"s article on Using Markdown for Effective Logging over at CodeProject. Here"s the first image borrowed from his excellent article where he clearly shows why Markdown is simpler than HTML:

    html-vs-md

    Stuart has taken Markdown and created a wonderful little library called MarkdownLog. It"s a brilliant little idea that one of us should have come up with first! Kudos to Stuart. ;)

    [MarkdownLog]is designed to make it trivial to produce Markdown formatted text from an application"s data structures. Using just one line of code, a collection of .NET objects can be output as a table or list. And, because the output is Markdown, it can later be converted to HTML for publishing, if needed.

    Even better, MarkdownLog is a Portable Class Library (PCL) and can be used with any .NET platform, including iOS with Xamarin. In fact, it"s an iPhone app written with Xamarin that compelled Stuart to write MarkdownLog.

    Here"s one of his first examples. This C# code:

    var myStrings = new { "John", "Paul", "Ringo", "George" };
    Console.Write(myStrings.ToMarkdownBulletedList());

    Gives you this simple Markdown.

     * John
    * Paul
    * Ringo
    * George

    At this point, you are likely unimpressed. But wait! There"s more! There"s a whole series of nice extension methods that make it easy to create templates from objects of any shape. Here"s another example of his:

    var data = new 
    {
    new{Name = "Meryl Streep", Nominations = 18, Awards=3},
    new{Name = "Katharine Hepburn", Nominations = 12, Awards=4},
    new{Name = "Jack Nicholson", Nominations = 12, Awards=3}
    };

    Console.Write(data.ToMarkdownTable());

    This gives you a Markdown table, of course. This looks nothing like an HTML table, but remember, Markdown is source code that can be translated into other formats like HTML and PDF.

     Name | Nominations | Awards
    ----------------- | -----------:| ------:
    Meryl Streep | 18 | 3
    Katharine Hepburn | 12 | 4
    Jack Nicholson | 12 | 3

    Be sure to explore the full CodeProject article and the home page for MarkdownLog. Think about how you could add this to your existing logging framework and create better logs for tests, builds, anything. Take a look at the HTML render of one of Stuarts"s Test Suite Runs and tell me that you want immediately want to get to work updating your old .LOG files.

    Related Links


    SOURCE: http://www.hanselman.com/blog/NuGetPackageOfTheWeekMarkdownLogMakesLogFilesMuchPrettier.aspx

0 comments:

Post a Comment