diff options
author | Stephane Delcroix <stephane@delcroix.org> | 2016-11-15 20:39:48 +0100 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-11-15 11:39:48 -0800 |
commit | a6bbed029c64d2d64b74eeb67e27a099abf70664 (patch) | |
tree | 551c3924c055e2d39592b3f1c726cca46924dd73 /Xamarin.Forms.Build.Tasks/Logger.cs | |
parent | 14e21dcebd4a706aaa5eed384b142957d84df002 (diff) | |
download | xamarin-forms-a6bbed029c64d2d64b74eeb67e27a099abf70664.tar.gz xamarin-forms-a6bbed029c64d2d64b74eeb67e27a099abf70664.tar.bz2 xamarin-forms-a6bbed029c64d2d64b74eeb67e27a099abf70664.zip |
[XamlC] TypedBindings, some tests, a compiler, ... (#489)
Diffstat (limited to 'Xamarin.Forms.Build.Tasks/Logger.cs')
-rw-r--r-- | Xamarin.Forms.Build.Tasks/Logger.cs | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/Xamarin.Forms.Build.Tasks/Logger.cs b/Xamarin.Forms.Build.Tasks/Logger.cs new file mode 100644 index 00000000..b706e610 --- /dev/null +++ b/Xamarin.Forms.Build.Tasks/Logger.cs @@ -0,0 +1,76 @@ +using System; +using System.Xml; +using Microsoft.Build.Utilities; +using Xamarin.Forms.Xaml; + +namespace Xamarin.Forms.Build.Tasks +{ + public class Logger { + public TaskLoggingHelper Helper { get; } + public int Verbosity { get; } + + public Logger(TaskLoggingHelper helper, int verbosity) + { + Verbosity = verbosity; + Helper = helper; + } + + string buffer = ""; + + public void LogException(string subcategory, string errorCode, string helpKeyword, string file, Exception e) + { + var xpe = e as XamlParseException; + var xe = e as XmlException; + if (xpe != null) + LogError(subcategory, errorCode, helpKeyword, file, xpe.XmlInfo.LineNumber, xpe.XmlInfo.LinePosition, 0, 0, xpe.Message, xpe.HelpLink, xpe.Source); + else if (xe != null) + LogError(subcategory, errorCode, helpKeyword, file, xe.LineNumber, xe.LinePosition, 0, 0, xe.Message, xe.HelpLink, xe.Source); + else + LogError(subcategory, errorCode, helpKeyword, file, 0, 0, 0, 0, e.Message, e.HelpLink, e.Source); + } + + public void LogError(string subcategory, string errorCode, string helpKeyword, string file, int lineNumber, + int columnNumber, int endLineNumber, int endColumnNumber, string message, params object [] messageArgs) + { + if (!string.IsNullOrEmpty(buffer)) + LogLine(-1, null, null); + if (Helper != null) { + Helper.LogError(subcategory, errorCode, helpKeyword, file, lineNumber, columnNumber, endLineNumber, + endColumnNumber, message, messageArgs); + } else + Console.Error.WriteLine($"{file} ({lineNumber}:{columnNumber}) : {message}"); + } + + public void LogLine(int level, string format, params object [] arg) + { + if (!string.IsNullOrEmpty(buffer)) { + format = buffer + format; + buffer = ""; + } + + if (level < 0) { + if (Helper != null) + Helper.LogError(format, arg); + else + Console.Error.WriteLine(format, arg); + } else if (level <= Verbosity) { + if (Helper != null) + Helper.LogMessage(format, arg); + else + Console.WriteLine(format, arg); + } + } + + public void LogString(int level, string format, params object [] arg) + { + if (level <= 0) + Console.Error.Write(format, arg); + else if (level <= Verbosity) { + if (Helper != null) + buffer += String.Format(format, arg); + else + Console.Write(format, arg); + } + } + } +}
\ No newline at end of file |