Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/xamarin/macdoc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremie Laval <jeremie.laval@gmail.com>2012-11-21 17:46:21 +0400
committerJeremie Laval <jeremie.laval@gmail.com>2012-11-21 17:47:46 +0400
commit88f139eaa6ece353bad2d7e504a8efe2dfc809f4 (patch)
tree568bd17bd6724c06d3ec236a39436ef3124f137e
parentc8ed30fa822ef6bc2f489b539a5ffb9f64ad30f7 (diff)
[macdoc] The modern man writes its own logger
-rw-r--r--AppDelegate.cs6
-rw-r--r--AppleDocMergeWindowController.cs2
-rw-r--r--BookmarkAssistantController.cs2
-rw-r--r--IndexUpdateManager.cs4
-rw-r--r--Logger.cs28
-rw-r--r--MyDocument.cs10
-rw-r--r--macdoc.csproj1
7 files changed, 38 insertions, 15 deletions
diff --git a/AppDelegate.cs b/AppDelegate.cs
index ca8559d..2a43a8c 100644
--- a/AppDelegate.cs
+++ b/AppDelegate.cs
@@ -130,12 +130,12 @@ namespace macdoc
var indexManager = IndexUpdateManager;
indexManager.CheckIndexIsFresh ().ContinueWith (t => {
if (t.IsFaulted)
- Console.WriteLine ("Error while checking indexes: {0}", t.Exception);
+ Logger.LogError ("Error while checking indexes", t.Exception);
else if (!t.Result)
indexManager.PerformSearchIndexCreation ();
else
indexManager.AdvertiseFreshIndex ();
- }).ContinueWith (t => Console.WriteLine ("Error while creating indexes: {0}", t.Exception), TaskContinuationOptions.OnlyOnFaulted);
+ }).ContinueWith (t => Logger.LogError ("Error while creating indexes", t.Exception), TaskContinuationOptions.OnlyOnFaulted);
// Check if there is a MonoTouch documentation installed and launch accordingly
if (Root.HelpSources.Cast<HelpSource> ().Any (hs => hs != null && hs.Name != null && hs.Name.StartsWith ("MonoTouch", StringComparison.InvariantCultureIgnoreCase))
@@ -148,7 +148,7 @@ namespace macdoc
mergeOutdated = AppleDocHandler.CheckMergedDocumentationFreshness (infos);
return Tuple.Create (docOutdated || mergeOutdated, docOutdated, mergeOutdated);
}).ContinueWith (t => {
- Console.WriteLine ("Merged status {0}", t.Result);
+ Logger.Log ("Merged status {0}", t.Result);
if (!t.Result.Item1)
return;
BeginInvokeOnMainThread (() => LaunchDocumentationUpdate (t.Result.Item2, t.Result.Item3));
diff --git a/AppleDocMergeWindowController.cs b/AppleDocMergeWindowController.cs
index d0c8e47..495e43a 100644
--- a/AppleDocMergeWindowController.cs
+++ b/AppleDocMergeWindowController.cs
@@ -41,7 +41,7 @@ namespace macdoc
var faulted = t.IsFaulted;
if (faulted)
- Console.WriteLine ("Merger exception: " + t.Exception.ToString ());
+ Logger.LogError ("Merger exception", t.Exception);
BeginInvokeOnMainThread (() => Finish (faulted || t.Result > 0, faulted ? 99 : t.Result));
});
diff --git a/BookmarkAssistantController.cs b/BookmarkAssistantController.cs
index 4baaa05..86ba6d3 100644
--- a/BookmarkAssistantController.cs
+++ b/BookmarkAssistantController.cs
@@ -32,7 +32,7 @@ namespace macdoc
{
var entry = entries[row];
AppDelegate.BookmarkManager.DeleteBookmark (entry);
- Console.WriteLine ("Removed entry {0}", entry.Name);
+ Logger.Log ("Removed entry {0}", entry.Name);
View.TableView.ReloadData ();
}
diff --git a/IndexUpdateManager.cs b/IndexUpdateManager.cs
index 2a2279e..190b0bf 100644
--- a/IndexUpdateManager.cs
+++ b/IndexUpdateManager.cs
@@ -22,7 +22,7 @@ namespace macdoc
public IndexUpdateManager (IEnumerable<string> sourceFiles, string baseUserDir)
{
- Console.WriteLine ("Going to verify [{0}]", sourceFiles.Aggregate ((e1, e2) => e1 + ", " + e2));
+ Logger.Log ("Going to verify [{0}]", sourceFiles.Aggregate ((e1, e2) => e1 + ", " + e2));
this.baseUserDir = baseUserDir;
this.sourceFiles = sourceFiles;
}
@@ -61,7 +61,7 @@ namespace macdoc
md5sums[source] = hash;
}
- Console.WriteLine ("We have a {0} fresh index", isFresh);
+ Logger.Log ("Index fresh? {0}", isFresh ? "yes" : "no");
return IsFresh = isFresh;
});
diff --git a/Logger.cs b/Logger.cs
index 1c6e111..b98a48f 100644
--- a/Logger.cs
+++ b/Logger.cs
@@ -1,11 +1,35 @@
using System;
+using System.IO;
namespace macdoc
{
- public class Logger
+ public static class Logger
{
- public Logger ()
+ static readonly string LogFilePath;
+
+ static Logger ()
+ {
+ var baseLogFolder = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.Personal), "Library", "Logs", "MacDoc");
+ if (!Directory.Exists (baseLogFolder))
+ Directory.CreateDirectory (baseLogFolder);
+ LogFilePath = Path.Combine (baseLogFolder, string.Format ("MacDoc-{0}.log", DateTime.Now.ToString ("s")));
+ }
+
+ public static void Log (string message)
+ {
+ Console.WriteLine (message);
+ File.AppendAllText (LogFilePath, message + Environment.NewLine);
+ }
+
+ public static void Log (string messageFormat, params object[] args)
+ {
+ Log (string.Format (messageFormat, args));
+ }
+
+ public static void LogError (string message, Exception ex)
{
+ Console.WriteLine (message + ": " + ex.Message);
+ File.AppendAllText (LogFilePath, message + ". " + ex.ToString () + Environment.NewLine);
}
}
}
diff --git a/MyDocument.cs b/MyDocument.cs
index 49a7554..d802858 100644
--- a/MyDocument.cs
+++ b/MyDocument.cs
@@ -53,13 +53,13 @@ namespace macdoc
toolbarSearchEntry.StringValue = searchTerm;
tabSelector.SelectAt (2);
Search (searchTerm);
- Console.WriteLine ("Searched: '{0}'", searchTerm);
+ Logger.Log ("Searched: '{0}'", searchTerm);
}
}
public override bool ReadFromUrl (NSUrl url, string typeName, out NSError outError)
{
- Console.WriteLine ("ReadFromUrl : {0}", url.ToString ());
+ Logger.Log ("ReadFromUrl: {0}", url.ToString ());
outError = null;
// if scheme is not right, we ignore the url
@@ -242,16 +242,14 @@ namespace macdoc
internal void LoadUrl (string url, bool syncTreeView = false, HelpSource source = null, bool addToHistory = true)
{
- if (url.StartsWith ("#")) {
- Console.WriteLine ("FIXME: Anchor jump");
+ if (url.StartsWith ("#"))
return;
- }
// In case user click on an external link e.g. [Android documentation] link at bottom of MonoDroid docs
if (url.StartsWith ("http://")) {
UrlLauncher.Launch (url);
return;
}
- Console.WriteLine ("Loading {0}", url);
+ Logger.Log ("Loading {0}", url);
var ts = Interlocked.Increment (ref loadUrlTimestamp);
Task.Factory.StartNew (() => {
Node node;
diff --git a/macdoc.csproj b/macdoc.csproj
index e883c54..4db6cdc 100644
--- a/macdoc.csproj
+++ b/macdoc.csproj
@@ -105,6 +105,7 @@
<Compile Include="AppleDocMergeWindow.designer.cs">
<DependentUpon>AppleDocMergeWindow.cs</DependentUpon>
</Compile>
+ <Compile Include="Logger.cs" />
</ItemGroup>
<ItemGroup>
<InterfaceDefinition Include="MyDocument.xib" xmlns="" />