public static void log(string level, string comp, string msg, Exception e)
{
if (comp == null) comp = "";
if (msg == null) msg = "";
var nowms = DateTimeMs.NowMs;
var ts = nowms.ToShortDateString().PadLeft(10) + " " + nowms.ToLongTimeString().PadLeft(8) + "." + nowms.Millisecond.ToString().PadLeft(3, '0');
msg = "["+level+"] "+ ts + "["+comp+"] " + msg;
if (e != null)
{
msg += "\n" + e.GetType().ToString() + ": " + e.Message +"\n"+ e.StackTrace;
}
if (e != null && e.GetBaseException() != null && e.GetBaseException() != e)
{
e = e.GetBaseException();
msg += "BaseException:\n" + e.GetType().ToString() + ": " + e.Message +"\n"+ e.StackTrace;
}
try{
System.Console.WriteLine(msg);
#if __ANDROID__
Android.Util.Log.Error("", msg);
#endif
if (fs != null)
{
fs.Write(msg+"\n");
fs.Flush();
}
}catch(Exception){}
}