Skip to content

Commit f1afc36

Browse files
committed
Added application startup logging for ViewModel and Device Manager classes
1 parent 7041571 commit f1afc36

26 files changed

Lines changed: 280 additions & 12 deletions

DeviceHub/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
<setting name="ServerLoggingEnabled" serializeAs="String">
2020
<value>False</value>
2121
</setting>
22+
<setting name="DeviceHubAppLoggingEnabled" serializeAs="String">
23+
<value>False</value>
24+
</setting>
2225
</ASCOM.DeviceHub.Properties.Settings>
2326
</applicationSettings>
2427
</configuration>

DeviceHub/Business Object Classes/ASCOM Classes/LocalServer.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,11 +1084,16 @@ private static bool ProcessArguments( string[] args )
10841084
retval = false;
10851085

10861086
break;
1087+
case "-enableapplogging":
1088+
case @"/enableapplogging":
1089+
Logger.LogMessage( msgId, "Enabling application startup logging." );
1090+
Globals.ForceAppLogging = true;
1091+
break;
10871092

10881093
default:
10891094
string msg = $"Unknown argument: {args[0]}";
10901095
Logger.LogMessage( msgId, msg );
1091-
msg += "\nValid are : -register, -unregister, unregister_full, and -embedding";
1096+
msg += "\nValid are : -register, -unregister, unregister_full, -embedding, and -enableapplogging";
10921097
string caption = GetAssemblyTitle();
10931098
MessageBox.Show( msg, caption, MessageBoxButton.OK, MessageBoxImage.Exclamation );
10941099

DeviceHub/Business Object Classes/Globals.cs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Threading.Tasks;
33

4+
using ASCOM.Utilities;
5+
46
namespace ASCOM.DeviceHub
57
{
68
public static class Globals
@@ -17,10 +19,10 @@ static Globals()
1719
public const double DegRad = Math.PI / 180.0;
1820
public const double UTC_SECS_PER_SIDEREAL_SEC = 0.9972695677;
1921

20-
public const double DEG_TO_RAD = ( 2.0 * Math.PI ) / 360.0; // 0.017453 radians per degree
21-
public const double RAD_TO_DEG = 1.0 / DEG_TO_RAD; // 57.29578 degrees per radian
22-
public const double HRS_TO_RAD = ( 2.0 * Math.PI ) / 24.0; // 0.26180 radians per hour
23-
public const double RAD_TO_HRS = 1.0 / HRS_TO_RAD; // 3.81972 hours per radian
22+
public const double DEG_TO_RAD = ( 2.0 * Math.PI ) / 360.0; // 0.017453 radians per degree
23+
public const double RAD_TO_DEG = 1.0 / DEG_TO_RAD; // 57.29578 degrees per radian
24+
public const double HRS_TO_RAD = ( 2.0 * Math.PI ) / 24.0; // 0.26180 radians per hour
25+
public const double RAD_TO_HRS = 1.0 / HRS_TO_RAD; // 3.81972 hours per radian
2426
public const double HRS_TO_DEG = 15.0; // 15 degrees per hour
2527

2628
public const double SCOPE_FAST_UPDATE_MIN = 0.5;
@@ -67,5 +69,26 @@ static Globals()
6769
public static DevHubTelescopeStatus LatestRawTelescopeStatus { get; set; }
6870

6971
public static TaskScheduler UISyncContext { get; set; }
72+
73+
public static bool ForceAppLogging { get; set; }
74+
75+
private static TraceLogger _appLogger = null;
76+
77+
public static TraceLogger AppLogger
78+
{
79+
get
80+
{
81+
if ( _appLogger == null )
82+
{
83+
_appLogger = new Utilities.TraceLogger( "", "DeviceHub.App" )
84+
{
85+
Enabled = Properties.Settings.Default.DeviceHubAppLoggingEnabled || ForceAppLogging,
86+
IdentifierWidth = 50
87+
};
88+
}
89+
90+
return _appLogger;
91+
}
92+
}
7093
}
7194
}

DeviceHub/DeviceManagers/DeviceManagerBase.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,18 @@ public class DeviceManagerBase : NormalizedValueBase, INotifyPropertyChanged
3232

3333
public DeviceManagerBase( DeviceTypeEnum deviceType )
3434
{
35+
string caller = $"DeviceManagerBase ctor for {deviceType}";
36+
37+
LogAppMessage( "Initializing Instance constructor", caller );
38+
3539
DeviceType = deviceType;
3640

3741
ThrowOnInvalidPropertyName = false;
3842
_messageBoxService = null;
3943

4044
Exceptions = new PropertyExceptions();
45+
46+
LogAppMessage( "Instance constructor initialization complete.", caller );
4147
}
4248

4349
public Exception GetLastPropertyException( [System.Runtime.CompilerServices.CallerMemberName] string propName = "???" )
@@ -311,6 +317,15 @@ private string GetMessageTypeName( ActivityMessageTypes msgType )
311317

312318
#endregion
313319

320+
#region Application Logging Methods
321+
322+
protected static void LogAppMessage( string message, [System.Runtime.CompilerServices.CallerMemberName] string callerName = "???" )
323+
{
324+
Globals.AppLogger.LogMessage( callerName, message );
325+
}
326+
327+
#endregion Application Logging Methods
328+
314329
#region Message Box Support Members
315330

316331
private IMessageBoxService _messageBoxService;

DeviceHub/DeviceManagers/DomeManager.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ public static DomeManager Instance
3939

4040
static DomeManager()
4141
{
42+
string caller = "DomeManager static ctor";
43+
44+
LogAppMessage( "Initialization started", caller );
45+
4246
DomeID = "";
4347
}
4448

@@ -74,6 +78,10 @@ public static void SetDomeID( string id )
7478
private DomeManager()
7579
: base( DeviceTypeEnum.Dome )
7680
{
81+
string caller = "DomeManager instance ctor";
82+
83+
LogAppMessage( "Initializing Instance constructor", caller );
84+
7785
IsConnected = false;
7886
Capabilities = null;
7987
Parameters = null;
@@ -88,10 +96,14 @@ private DomeManager()
8896
PollingPeriod = POLLING_INTERVAL_NORMAL;
8997
PollingChange = new ManualResetEvent( false );
9098

99+
LogAppMessage( "Registering message handlers.", caller );
100+
91101
Messenger.Default.Register<TelescopeParametersUpdatedMessage>( this, ( action ) => UpdateTelescopeParameters( action ) );
92102
Messenger.Default.Register<TelescopeStatusUpdatedMessage>( this, ( action ) => UpdateTelescopeStatus( action ) );
93103
Messenger.Default.Register<DeviceDisconnectedMessage>( this, ( action ) => ClearTelescopeStatus( action ) );
94104
Messenger.Default.Register<SlewInProgressMessage>( this, ( action ) => InitiateSlavedSlew( action ) );
105+
106+
LogAppMessage( "Instance constructor initialization complete.", caller );
95107
}
96108

97109
#endregion Instance Constructor

DeviceHub/DeviceManagers/FocuserManager.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ public static FocuserManager Instance
3434

3535
static FocuserManager()
3636
{
37+
string caller = "FocuserManager static ctor";
38+
39+
LogAppMessage( "Initialization started.", caller );
3740
FocuserID = "";
41+
LogAppMessage( "Initialization completed.", caller );
3842
}
3943

4044
public static void SetFocuserID( string id )
@@ -63,6 +67,9 @@ public static void SetFocuserID( string id )
6367
public FocuserManager()
6468
: base( DeviceTypeEnum.Focuser )
6569
{
70+
string caller = "FocuserManager instance ctor";
71+
LogAppMessage( "Initializing Instance constructor", caller );
72+
6673
IsConnected = false;
6774
Parameters = null;
6875
Status = null;
@@ -71,6 +78,8 @@ public FocuserManager()
7178
MoveInProgress = false;
7279
PollingPeriod = POLLING_PERIOD_NORMAL;
7380
PollingChange = new ManualResetEvent( false );
81+
82+
LogAppMessage( "Instance constructor initialization complete.", caller );
7483
}
7584

7685
#endregion Instance Constructor

DeviceHub/DeviceManagers/TelescopeManager.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,23 @@ public static TelescopeManager Instance
4343

4444
static TelescopeManager()
4545
{
46+
string caller = "TelescopeManager static ctor";
4647
TelescopeID = "";
48+
LogAppMessage( "Initialization started.", caller );
4749

48-
AstroUtils = new AstroUtils();
50+
try
51+
{
52+
LogAppMessage( "Creating AstroUtils instance", caller );
53+
54+
AstroUtils = new AstroUtils();
55+
}
56+
catch (Exception xcp)
57+
{
58+
string msg = $"Unable to create an instance of AstroUtils. Details follow:\r\n\r\n{xcp}";
59+
LogAppMessage( msg, "TelescopeManager static constructor" );
60+
}
61+
62+
LogAppMessage( "Initialization complete", caller );
4963
}
5064

5165
public static void SetTelescopeID( string id )
@@ -93,6 +107,9 @@ private DateTime PulseGuideEnd
93107
private TelescopeManager()
94108
: base( DeviceTypeEnum.Telescope )
95109
{
110+
string caller = "TelescopeManager instance ctor";
111+
LogAppMessage( "Initializing Instance constructor", caller );
112+
96113
IsConnected = false;
97114
Capabilities = null;
98115
Parameters = null;
@@ -105,6 +122,8 @@ private TelescopeManager()
105122
PollingChange = new ManualResetEvent( false );
106123

107124
PreviousSlewInProgressMessage = new SlewInProgressMessage( false );
125+
126+
LogAppMessage( "Instance constructor initialization complete.", caller );
108127
}
109128

110129
#endregion Instance Constructor

DeviceHub/Properties/Settings.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DeviceHub/Properties/Settings.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
<Setting Name="ServerLoggingEnabled" Type="System.Boolean" Scope="Application">
1212
<Value Profile="(Default)">False</Value>
1313
</Setting>
14+
<Setting Name="DeviceHubAppLoggingEnabled" Type="System.Boolean" Scope="Application">
15+
<Value Profile="(Default)">False</Value>
16+
</Setting>
1417
</Settings>
1518
</SettingsFile>

DeviceHub/ViewModel Classes/DeviceHubViewModelBase.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ protected MessageBoxResult ShowMessage( string text, string caption, MessageBoxB
6767

6868
#endregion MessageBox Helpers
6969

70+
#region App Logger Members
71+
72+
protected static void LogAppMessage( string message, [System.Runtime.CompilerServices.CallerMemberName] string callerName = "???" )
73+
{
74+
Globals.AppLogger.LogMessage( callerName, message );
75+
}
76+
77+
#endregion App Logger Members
78+
7079
#region INotifyPropertyChanged Members
7180

7281
/// <summary>

0 commit comments

Comments
 (0)