A year back, published a(n ill-named) package (Prolog) to rid the day of tedious Console.Write
/Debug.Log
cycles. Powered by Mono.Cecil, took upon itself to log every function call.
If memory serves, did/does work pretty well.
So why are we here? Reasons - TLDR old habits die. harder. So here is an article about logging in C# for debugging purposes. The bread and lobster.
And how I am fixing it.
Wait, logging is broken in C#?
PowerShell got brogging rights -
# Say 'Hi'
"Hi"
From here, all downhill. Be it .net or Unity3D, an assortment of Console.Write
/ Debug.Log
/ [insert pompous paraphernalia]
.
What logs in VS does not log in a console app does not log in Unity so, if you are going "cross platform", steam the logster yourself.
Can we fix this? What?
A casual logging API (re: PowerShell) should be concise and readable. We do ✨not✨ want a using
dep for the sake of debugging.
90% of the time we are going to remove these traces; the remaining 10% of the time use a dedicated logger (so we know not to delete user traces).
Ergo logging via system/engine level scoped (namespaced) APIs, this:
A DISTRACTION™️
Pure C# solution
Tried variants around...
++ log / $"message"; // (++/--) for severity?
⚠️ The above does not constitute a well formed C# statement. Unless willing to eat your shirt (we are getting there), go with 🌊
public static class Log{
public static void Message(object arg)
=> Console.WriteLine(arg);
}
Which you may use without using
, like so:
Log.Message("(\´ ∀ \`*)"); # print (´ ∀ `*)
Eat your shirt
So. Was looking into this while reviewing log traces in Howl, the symbolic notation for C# -
More about this later - question: what would be an idiom that shines 〜 usability, easy mapping to C# (bidi conversions with) and all
Been a week I been using Howl now logging like the 80s went back to the future 〜 #Howl and #CSharp #programming in #Unity (and later, .net)08:34 AM - 08 Aug 2020
Howl imp:
⊐̥ System.Console;
‒ ○ log{
‒̥ ㄹ message { ╰ → WriteLine(value); }
‒̥ ㄹ warning { ╰ → WriteLine(value); }
‒̥ ㄹ error { ╰ → WriteLine(value); }
}
We map chicks to lobsters internally.
// ... Howl internals
("🐤", "log.warning =", alt: "[chick]"),
// ... Have your chick and eat it too.
Next: preparing a small article about begin/end pattern annoyances and (pure C#) ways to kiss the beast 🖖🏼
Top comments (0)