CSDNCurrent en:Logging
Overview
Your client may retrieve its logging settings from the Cryptshare Server. This allows the administrator of a Cryptshare Server to specify the amount of information that is to be logged on the client. Furthermore, clients may send their log entries to the Cryptshare Server for the purpose of being logged remotely.
Retrieve Logging Settings
In order to retrieve the logging settings, simply instantiate a Client and call
var loggingSettings = client.GetLoggingSettings();
The result returns a LoggingSettings
object that specifies the log level to be used and whether the client is allowed to perform remote logging:
Console.WriteLine("Log Level: {0}", loggingSettings.Level); Console.WriteLine("Is Remote Logging enabled? {0}", loggingSettings.RemoteLoggingEnabled ? "Yes" : "No");
If your applications makes use of Task<T>
s and the async
/await
keywords, there is also an asynchronous method variant called client.GetLoggingSettingsAsync()
.
It may be necessary to send log entries produced by the client to the Cryptshare Server, e.g. if the client does not allow ad-hoc access to its file system for the inspection of log files. In such scenarios, the administrator may allow the client to send its log entries to the Cryptshare Server. This is achieved by adding the client's ID (accessible via client.ClientId
), an alphanumeric string unique to each client, to the list of clients that are allowed to perform remote logging. The following page describes the process in more detail: Remote Logging.
Assuming the client is allowed to perform remote logging (see usage of loggingSettings.RemoteLoggingEnabled
above), the log entries can be sent in the following way:
var logEntries = new LogEntry[] { new LogEntry(LogLevel.Warn, "This is a warning."), new LogEntry(LogLevel.Error, "This is an error."), }; client.SendLogEntries(logEntries);
If your applications makes use of Task<T>
s and the async
/await
keywords, there is also an asynchronous method variant called client.SendLogEntriesAsync()
.
If you send log entries despite remote logging not being enabled for the client, the method will throw a CryptshareServerException
with code 3004
.
Please note that sending log entries with a level that is lower than the level specified by the Cryptshare Server will not be logged remotely.
Whether you want to send each log entry separately or multiple log entries in bulk is up to you. Both approaches have their benefits and drawbacks: Sending log entries in bulk causes less network traffic, but if the application crashes, the most recent log entries may not have been sent to the Cryptshare Server. Sending each log entry separately has inverse set of benefits and drawbacks.