Refactored Logger.cs

This commit is contained in:
sta 2014-08-08 20:57:09 +09:00
parent e3941f9517
commit c1dd8d659e

View File

@ -46,7 +46,7 @@ namespace WebSocketSharp
/// </para> /// </para>
/// <para> /// <para>
/// If you would like to use the custom output action, you should set the /// If you would like to use the custom output action, you should set the
/// <see cref="Logger.Output"/> to any <c>Action&lt;LogData, string&gt;</c>. /// <see cref="Logger.Output"/> to any <c>Action&lt;LogData, string&gt;</c> delegate.
/// </para> /// </para>
/// </remarks> /// </remarks>
public class Logger public class Logger
@ -114,10 +114,10 @@ namespace WebSocketSharp
#region Public Properties #region Public Properties
/// <summary> /// <summary>
/// Gets or sets the path to the log file. /// Gets or sets the current path to the log file.
/// </summary> /// </summary>
/// <value> /// <value>
/// A <see cref="string"/> that represents the path to the log file if any. /// A <see cref="string"/> that represents the current path to the log file if any.
/// </value> /// </value>
public string File { public string File {
get { get {
@ -191,7 +191,7 @@ namespace WebSocketSharp
var log = data.ToString (); var log = data.ToString ();
Console.WriteLine (log); Console.WriteLine (log);
if (path != null && path.Length > 0) if (path != null && path.Length > 0)
writeToFile (path, log); writeToFile (log, path);
} }
private void output (string message, LogLevel level) private void output (string message, LogLevel level)
@ -212,12 +212,11 @@ namespace WebSocketSharp
} }
} }
private static void writeToFile (string path, string value) private static void writeToFile (string value, string path)
{ {
using (var writer = new StreamWriter (path, true)) using (var writer = new StreamWriter (path, true))
using (var syncWriter = TextWriter.Synchronized (writer)) { using (var syncWriter = TextWriter.Synchronized (writer))
syncWriter.WriteLine (value); syncWriter.WriteLine (value);
}
} }
#endregion #endregion
@ -228,8 +227,8 @@ namespace WebSocketSharp
/// Outputs <paramref name="message"/> as a log with <see cref="LogLevel.Debug"/>. /// Outputs <paramref name="message"/> as a log with <see cref="LogLevel.Debug"/>.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// If the current logging level is higher than <see cref="LogLevel.Debug"/>, this method /// If the current logging level is higher than <see cref="LogLevel.Debug"/>,
/// doesn't output <paramref name="message"/> as a log. /// this method doesn't output <paramref name="message"/> as a log.
/// </remarks> /// </remarks>
/// <param name="message"> /// <param name="message">
/// A <see cref="string"/> that represents the message to output as a log. /// A <see cref="string"/> that represents the message to output as a log.
@ -246,8 +245,8 @@ namespace WebSocketSharp
/// Outputs <paramref name="message"/> as a log with <see cref="LogLevel.Error"/>. /// Outputs <paramref name="message"/> as a log with <see cref="LogLevel.Error"/>.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// If the current logging level is higher than <see cref="LogLevel.Error"/>, this method /// If the current logging level is higher than <see cref="LogLevel.Error"/>,
/// doesn't output <paramref name="message"/> as a log. /// this method doesn't output <paramref name="message"/> as a log.
/// </remarks> /// </remarks>
/// <param name="message"> /// <param name="message">
/// A <see cref="string"/> that represents the message to output as a log. /// A <see cref="string"/> that represents the message to output as a log.
@ -275,8 +274,8 @@ namespace WebSocketSharp
/// Outputs <paramref name="message"/> as a log with <see cref="LogLevel.Info"/>. /// Outputs <paramref name="message"/> as a log with <see cref="LogLevel.Info"/>.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// If the current logging level is higher than <see cref="LogLevel.Info"/>, this method /// If the current logging level is higher than <see cref="LogLevel.Info"/>,
/// doesn't output <paramref name="message"/> as a log. /// this method doesn't output <paramref name="message"/> as a log.
/// </remarks> /// </remarks>
/// <param name="message"> /// <param name="message">
/// A <see cref="string"/> that represents the message to output as a log. /// A <see cref="string"/> that represents the message to output as a log.
@ -293,8 +292,8 @@ namespace WebSocketSharp
/// Outputs <paramref name="message"/> as a log with <see cref="LogLevel.Trace"/>. /// Outputs <paramref name="message"/> as a log with <see cref="LogLevel.Trace"/>.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// If the current logging level is higher than <see cref="LogLevel.Trace"/>, this method /// If the current logging level is higher than <see cref="LogLevel.Trace"/>,
/// doesn't output <paramref name="message"/> as a log. /// this method doesn't output <paramref name="message"/> as a log.
/// </remarks> /// </remarks>
/// <param name="message"> /// <param name="message">
/// A <see cref="string"/> that represents the message to output as a log. /// A <see cref="string"/> that represents the message to output as a log.
@ -311,8 +310,8 @@ namespace WebSocketSharp
/// Outputs <paramref name="message"/> as a log with <see cref="LogLevel.Warn"/>. /// Outputs <paramref name="message"/> as a log with <see cref="LogLevel.Warn"/>.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// If the current logging level is higher than <see cref="LogLevel.Warn"/>, this method /// If the current logging level is higher than <see cref="LogLevel.Warn"/>,
/// doesn't output <paramref name="message"/> as a log. /// this method doesn't output <paramref name="message"/> as a log.
/// </remarks> /// </remarks>
/// <param name="message"> /// <param name="message">
/// A <see cref="string"/> that represents the message to output as a log. /// A <see cref="string"/> that represents the message to output as a log.