ludodepaz
2 years agoContributor
Log anything with JSON
I showed it at Wave and share it with all of you: when you use JSON to log, you can log anything, not just strings, you can log a Dictionary, a list, a MemberInfo, even a Databuffer.
First, you need to import JSON, add these 2 rows at the top of your rule:
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
Second, when you want to log, use JSON!
Dim stringobj As String = JsonConvert.SerializeObject(lCenterInfo,Formatting.Indented)
api.logmessage(lCenterInfo.Member.Name & ", lCenterInfo: " & stringobj)
When you use ,Formatting.Indented, your log will be correctly formatted.
Thanks to Matt Ha for enlightening me with JSON and RobbSalzmann for sharing how to have the JSON string correctly formatted!