Skip to content

Commit bcac5a1

Browse files
authored
Merge pull request #4 from tomdam/dev-logging-to-log-window
Adding the possibility to write to Log window from all modules.
2 parents c19a1c0 + b4db860 commit bcac5a1

File tree

7 files changed

+44
-13
lines changed

7 files changed

+44
-13
lines changed

src/SPCoder.Core/SPCoder.Core.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<Compile Include="Utils\Common.cs" />
7272
<Compile Include="Utils\CrossThreadFormsExtensions.cs" />
7373
<Compile Include="Utils\Delegates.cs" />
74+
<Compile Include="Utils\ISPCoderLog.cs" />
7475
<Compile Include="Utils\Logging.cs" />
7576
<Compile Include="Utils\ModuleDescription.cs" />
7677
<Compile Include="Utils\Nodes\BaseActionItem.cs" />
@@ -80,6 +81,7 @@
8081
<Compile Include="Utils\ObjectModelType.cs" />
8182
<Compile Include="Utils\ShellIcon.cs" />
8283
<Compile Include="Utils\SPCoderConstants.cs" />
84+
<Compile Include="Utils\SPCoderLogger.cs" />
8385
</ItemGroup>
8486
<ItemGroup>
8587
<None Include="packages.config" />
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
52

6-
namespace SPCoder.Windows
3+
namespace SPCoder.Core.Utils
74
{
85
public interface ISPCoderLog
96
{
107
void AppendToLog(string text, bool logTimestamp = true);
118
void LogError(string text, bool logTimestamp = true);
9+
void LogError(Exception exception, bool logTimestamp = true);
1210
void LogWarning(string text, bool logTimestamp = true);
1311
void LogInfo(string text, bool logTimestamp = true);
1412
}
15-
}
13+
}

src/SPCoder.Core/Utils/Logging.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ public static ILog Logger
2020
}
2121
}
2222
}
23+
2324
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace SPCoder.Core.Utils
8+
{
9+
public class SPCoderLogger
10+
{
11+
private static ISPCoderLog m_logger;
12+
13+
public static ISPCoderLog Logger {
14+
set
15+
{
16+
m_logger = value;
17+
}
18+
19+
get
20+
{
21+
return m_logger;
22+
}
23+
}
24+
}
25+
}

src/SPCoder.FileSystem/Utils/FSConnector.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
using SPCoder.FileSystem.Utils.Nodes;
1+
using SPCoder.Core.Utils;
2+
using SPCoder.FileSystem.Utils.Nodes;
23
using SPCoder.Utils;
34
using SPCoder.Utils.Nodes;
45
using System;
56
using System.Collections.Generic;
67
using System.Drawing;
78
using System.IO;
8-
using System.Linq;
9-
using System.Text;
10-
using System.Threading.Tasks;
119

1210
namespace SPCoder.FileSystem.Utils
1311
{
14-
12+
1513
public class FSConnector : BaseConnector
1614
{
1715
DirectoryInfo Folder { get; set; }
@@ -38,7 +36,8 @@ public override SPCoder.Utils.Nodes.BaseNode GetSPStructure(string siteUrl)
3836

3937
public override BaseNode ExpandNode(BaseNode node, bool doIfLoaded = false)
4038
{
41-
//Ako je web node
39+
SPCoderLogger.Logger.LogInfo("Expanding " + node.Url);
40+
//Ako je folder node
4241
if (node is FolderNode)
4342
{
4443
//Ako nije ucitan

src/SPCoder.WinApp/SPCoder.WinApp.2016.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,6 @@
333333
<Compile Include="Windows\GridViewer.Designer.cs">
334334
<DependentUpon>GridViewer.cs</DependentUpon>
335335
</Compile>
336-
<Compile Include="Windows\ISPCoderLog.cs" />
337336
<Compile Include="Windows\Log.cs">
338337
<SubType>Form</SubType>
339338
</Compile>

src/SPCoder.WinApp/Windows/Log.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using FastColoredTextBoxNS;
2+
using SPCoder.Core.Utils;
23
using System;
34
using System.Collections.Generic;
45
using System.ComponentModel;
@@ -28,7 +29,8 @@ public Log()
2829
{
2930
InitializeComponent();
3031
//RtLog = rtLog;
31-
32+
//registering the logger so that other modules can write to SPCoder log window
33+
SPCoderLogger.Logger = this;
3234
}
3335

3436
public void AppendToLog(string text, bool logTimestamp = true)
@@ -42,6 +44,11 @@ public void LogError(string text, bool logTimestamp = true)
4244
LogText(text, errorStyle, logTimestamp);
4345
}
4446

47+
public void LogError(Exception exception, bool logTimestamp = true)
48+
{
49+
string text = exception.Message + "\n" + exception.StackTrace;
50+
LogText(text, errorStyle, logTimestamp);
51+
}
4552
public void LogWarning(string text, bool logTimestamp = true)
4653
{
4754
LogText(text, warningStyle, logTimestamp);

0 commit comments

Comments
 (0)