MvvmCross DebugTrace everything is routed using a single-line implementation of IMvxTrace
Each platform provides various implementations of this:
- on Windows platforms,
Debug tracing is used (since Trace itself is not available on all Windows platforms) - Android uses a double log of both
Debug and Android log - iOS uses a double log of both
Debug and iOS Console
This worked well in earlier versions of MvvmCross, especially where people directly linked to the MvvmCross source code and therefore could directly link to the MvvmCross debug or release binaries.
However ... because people are increasingly using the Nuget Binaries release, in which Debug is of course compiled, then this often leaves people asking "How to use it?"
The easiest way is to override IMvxTrace initialization in your Setup class.
This is easy to do - for example:
protected override IMvxTrace CreateDebugTrace() { return new MyDebugTrace(); }
where MyDebugTrace is something like:
public class MyDebugTrace : IMvxTrace { public void Trace(MvxTraceLevel level, string tag, Func<string> message) { Debug.WriteLine(tag + ":" + level + ":" + message()); } public void Trace(MvxTraceLevel level, string tag, string message) { Debug.WriteLine(tag + ":" + level + ":" + message); } public void Trace(MvxTraceLevel level, string tag, string message, params object[] args) { try { Debug.WriteLine(string.Format(tag + ":" + level + ":" + message, args)); } catch (FormatException) { Trace(MvxTraceLevel.Error, tag, "Exception during trace of {0} {1} {2}", level, message); } } }
If you want to enable various implementations for debug / release; if you want to enable or disable it at run time; if you want to filter on MvxTraceLevel or tag ; or if you want to use some kind of third-party logging mechanism, this should also be easy to do using simple C # on each platform.
Stuart
source share