Logging and more Service setup

This commit is contained in:
Cyberboss
2017-10-24 16:07:44 -04:00
parent df663d8eb1
commit 42a98df47b
16 changed files with 235 additions and 134 deletions
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.ServiceModel;
using TGServiceInterface.Components;
@@ -15,6 +16,10 @@ namespace TGServerService
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single)]
sealed partial class ServerInstance : IDisposable, ITGConnectivity
{
/// <summary>
/// Used to assign the instance to event IDs
/// </summary>
public readonly byte LoggingID;
/// <summary>
/// The configuration settings for the instance
/// </summary>
@@ -22,8 +27,9 @@ namespace TGServerService
/// <summary>
/// Constructs and a <see cref="ServerInstance"/>
/// </summary>
public ServerInstance(InstanceConfig config)
public ServerInstance(InstanceConfig config, byte logID)
{
LoggingID = logID;
Config = config;
FindTheDroidsWereLookingFor();
InitEventHandlers();
@@ -46,6 +52,46 @@ namespace TGServerService
DisposeChat();
}
/// <summary>
/// Writes information to the Windows event log
/// </summary>
/// <param name="message">The log message</param>
/// <param name="id">The <see cref="EventID"/> of the message</param>
void WriteInfo(string message, EventID id)
{
Service.WriteEntry(message, id, EventLogEntryType.Information, LoggingID);
}
/// <summary>
/// Writes an error to the Windows event log
/// </summary>
/// <param name="message">The log message</param>
/// <param name="id">The <see cref="EventID"/> of the message</param>
void WriteError(string message, EventID id)
{
Service.WriteEntry(message, id, EventLogEntryType.Error, LoggingID);
}
/// <summary>
/// Writes a warning to the Windows event log
/// </summary>
/// <param name="message">The log message</param>
/// <param name="id">The <see cref="EventID"/> of the message</param>
void WriteWarning(string message, EventID id)
{
Service.WriteEntry(message, id, EventLogEntryType.Warning, LoggingID);
}
/// <summary>
/// Writes an access event to the Windows event log
/// </summary>
/// <param name="username">The (un)authenticated Windows user's name</param>
/// <param name="authSuccess"><see langword="true"/> if <paramref name="username"/> authenticated sucessfully, <see langword="false"/> otherwise</param>
void WriteAccess(string username, bool authSuccess)
{
Service.WriteEntry(String.Format("Access from: {0}", username), EventID.Authentication, authSuccess ? EventLogEntryType.SuccessAudit : EventLogEntryType.FailureAudit, LoggingID);
}
/// <inheritdoc />
public string Version()
{