diff --git a/websocket-sharp/LogData.cs b/websocket-sharp/LogData.cs index db65d21f..3c142f14 100644 --- a/websocket-sharp/LogData.cs +++ b/websocket-sharp/LogData.cs @@ -30,13 +30,13 @@ using System; using System.Diagnostics; using System.Text; -namespace WebSocketSharp { - +namespace WebSocketSharp +{ /// /// Represents the log data used by the class. /// - public class LogData { - + public class LogData + { #region Private Fields private StackFrame _caller; @@ -48,12 +48,12 @@ namespace WebSocketSharp { #region Internal Constructors - internal LogData (DateTime date, LogLevel level, StackFrame caller, string message) + internal LogData (LogLevel level, StackFrame caller, string message) { - _date = date; _level = level; _caller = caller; _message = message; + _date = DateTime.Now; } #endregion diff --git a/websocket-sharp/LogLevel.cs b/websocket-sharp/LogLevel.cs index 9cbdd02d..b6001f08 100644 --- a/websocket-sharp/LogLevel.cs +++ b/websocket-sharp/LogLevel.cs @@ -28,13 +28,13 @@ using System; -namespace WebSocketSharp { - +namespace WebSocketSharp +{ /// /// Contains the values of the logging level. /// - public enum LogLevel { - + public enum LogLevel + { /// /// Indicates the bottom logging level. /// diff --git a/websocket-sharp/Logger.cs b/websocket-sharp/Logger.cs index 3cffd7ac..00fbb79b 100644 --- a/websocket-sharp/Logger.cs +++ b/websocket-sharp/Logger.cs @@ -30,8 +30,8 @@ using System; using System.Diagnostics; using System.IO; -namespace WebSocketSharp { - +namespace WebSocketSharp +{ /// /// Provides the simple logging functions. /// @@ -39,20 +39,20 @@ namespace WebSocketSharp { /// /// The Logger class provides some methods that output the logs associated with the each /// values. - /// If the value associated with a log was less than the , - /// the log could not be outputted. + /// If the value associated with a log is less than the , + /// the log can not be outputted. /// /// /// The default output action used by the output methods outputs the log data to the standard output stream /// and writes the same log data to the if it has a valid path. /// /// - /// If you wanted to run your custom output action, you would replace the current output action with + /// If you want to run custom output action, you can replace the current output action with /// your output action by using the method. /// /// - public class Logger { - + public class Logger + { #region Private Fields private volatile string _file; @@ -72,7 +72,7 @@ namespace WebSocketSharp { /// initializes the path to the log file with . /// public Logger () - : this (LogLevel.ERROR, null, defaultOutput) + : this (LogLevel.ERROR, null, null) { } @@ -87,7 +87,7 @@ namespace WebSocketSharp { /// One of the values to initialize. /// public Logger (LogLevel level) - : this (level, null, defaultOutput) + : this (level, null, null) { } @@ -104,18 +104,14 @@ namespace WebSocketSharp { /// /// /// An Action<LogData, string> delegate that references the method(s) to initialize. - /// A parameter to pass to the method(s) is the value of + /// A parameter to pass to the method(s) is the value of the /// if any. /// public Logger (LogLevel level, string file, Action output) { _level = level; _file = file; - if (output != null) - _output = output; - else - _output = defaultOutput; - + _output = output != null ? output : defaultOutput; _sync = new object (); } @@ -127,7 +123,7 @@ namespace WebSocketSharp { /// Gets or sets the path to the log file. /// /// - /// A that contains a path to the log file. + /// A that contains a path to the log file if any. /// public string File { get { @@ -138,6 +134,7 @@ namespace WebSocketSharp { lock (_sync) { _file = value; + Warn (String.Format ("The current path to the log file has been changed to {0}.", _file ?? "")); } } } @@ -158,6 +155,7 @@ namespace WebSocketSharp { set { _level = value; + Warn (String.Format ("The current logging level has been changed to {0}.", _level)); } } @@ -173,7 +171,7 @@ namespace WebSocketSharp { writeLine (log, path); } - private void output (LogLevel level, string message) + private void output (string message, LogLevel level) { if (level < _level || message == null || message.Length == 0) return; @@ -182,11 +180,11 @@ namespace WebSocketSharp { { LogData data = null; try { - data = new LogData (DateTime.Now, level, new StackFrame (2, true), message); + data = new LogData (level, new StackFrame (2, true), message); _output (data, _file); } catch (Exception ex) { - data = new LogData (DateTime.Now, LogLevel.FATAL, new StackFrame (0, true), ex.Message); + data = new LogData (LogLevel.FATAL, new StackFrame (0, true), ex.Message); Console.WriteLine (data.ToString ()); } } @@ -206,116 +204,114 @@ namespace WebSocketSharp { #region Public Methods /// - /// Outputs the specified as a log with the . + /// Outputs the specified as a log with the . /// /// - /// This method does not output as a log - /// if the current logging level is greater than the . + /// If the current logging level is greater than the , + /// this method does not output as a log. /// /// /// A that contains a message to output as a log. /// public void Debug (string message) { - output (LogLevel.DEBUG, message); + output (message, LogLevel.DEBUG); } /// - /// Outputs the specified as a log with the . + /// Outputs the specified as a log with the . /// /// - /// This method does not output as a log - /// if the current logging level is greater than the . + /// If the current logging level is greater than the , + /// this method does not output as a log. /// /// /// A that contains a message to output as a log. /// public void Error (string message) { - output (LogLevel.ERROR, message); + output (message, LogLevel.ERROR); } /// - /// Outputs the specified as a log with the . + /// Outputs the specified as a log with the . /// /// - /// This method does not output as a log - /// if the current logging level is greater than the . + /// If the current logging level is greater than the , + /// this method does not output as a log. /// /// /// A that contains a message to output as a log. /// public void Fatal (string message) { - output (LogLevel.FATAL, message); + output (message, LogLevel.FATAL); } /// - /// Outputs the specified as a log with the . + /// Outputs the specified as a log with the . /// /// - /// This method does not output as a log - /// if the current logging level is greater than the . + /// If the current logging level is greater than the , + /// this method does not output as a log. /// /// /// A that contains a message to output as a log. /// public void Info (string message) { - output (LogLevel.INFO, message); + output (message, LogLevel.INFO); } /// /// Replaces the current output action with the specified action. /// /// - /// This method replaces the current output action with the default output action - /// if is . + /// If is , + /// this method replaces the current output action with the default output action. /// /// /// An Action<LogData, string> delegate that references the method(s) to set. - /// A parameter to pass to the method(s) is the value of + /// A parameter to pass to the method(s) is the value of the /// if any. /// public void SetOutput (Action output) { lock (_sync) { - if (output != null) - _output = output; - else - _output = defaultOutput; + _output = output != null ? output : defaultOutput; + Warn ("The current output action has been replaced."); } } /// - /// Outputs the specified as a log with the . + /// Outputs the specified as a log with the . /// /// - /// This method does not output as a log - /// if the current logging level is greater than the . + /// If the current logging level is greater than the , + /// this method does not output as a log. /// /// /// A that contains a message to output as a log. /// public void Trace (string message) { - output (LogLevel.TRACE, message); + output (message, LogLevel.TRACE); } /// - /// Outputs the specified as a log with the . + /// Outputs the specified as a log with the . /// /// - /// This method does not output as a log - /// if the current logging level is greater than the . + /// If the current logging level is greater than the , + /// this method does not output as a log. /// /// /// A that contains a message to output as a log. /// public void Warn (string message) { - output (LogLevel.WARN, message); + output (message, LogLevel.WARN); } #endregion