From 3c42d0d8b27c8303c7d82bb1b7457bd00a76719d Mon Sep 17 00:00:00 2001 From: Holger Vetter Date: Tue, 19 Sep 2017 11:26:34 +0200 Subject: [PATCH] fix naming of Scope/AdditionalParams methods --- Daenet.Common.Logging/ILogManager.cs | 12 ++- Daenet.Common.Logging/LogManager.cs | 151 +++++++++++++++++---------- 2 files changed, 108 insertions(+), 55 deletions(-) diff --git a/Daenet.Common.Logging/ILogManager.cs b/Daenet.Common.Logging/ILogManager.cs index d34d0ec..dbd37bb 100644 --- a/Daenet.Common.Logging/ILogManager.cs +++ b/Daenet.Common.Logging/ILogManager.cs @@ -8,17 +8,27 @@ public interface ILogManager Dictionary CurrentScope { get; } string SourceName { get; } - void AddAdditionalParams(string scopeName, string scopeValue); + void AddAdditionalParams(string paramName, string paramValue); + [Obsolete("Use AddAdditionalParams(string paramName, string paramValue) instead.")] + void AddScope(string scopeName, string scopeValue); + IDisposable BeginScope(TState state); + IDisposable BeginScope(string messageFormat, params object[] args); void ClearScope(); void Close(); void Dispose(); + void RemoveAdditionalParams(string paramName); + [Obsolete("Use RemoveAdditionalParams(string paramName) instead.")] void RemoveScope(string scopeName); void TraceCritical(int eventId, Exception err, string msg, params object[] myParams); void TraceCritical(int eventId, string msg, params object[] myParams); void TraceDebug(int eventId, string msg, params object[] myParams); void TraceError(TracingLevel traceLevel, int eventId, Exception err, string msg, params object[] myParams); void TraceError(TracingLevel traceLevel, int eventId, string msg, params object[] myParams); + void TraceError(int eventId, string msg, params object[] myParams); + void TraceError(int eventId, Exception err, string msg, params object[] myParams); void TraceMessage(TracingLevel traceLevel, int eventId, string msg, params object[] myParams); + void TraceMessage(int eventId, string msg, params object[] myParams); void TraceWarning(TracingLevel traceLevel, int eventId, string msg, params object[] myParams); + void TraceWarning(int eventId, string msg, params object[] myParams); } } \ No newline at end of file diff --git a/Daenet.Common.Logging/LogManager.cs b/Daenet.Common.Logging/LogManager.cs index 781ef82..660540a 100644 --- a/Daenet.Common.Logging/LogManager.cs +++ b/Daenet.Common.Logging/LogManager.cs @@ -135,7 +135,7 @@ public LogManager(ILoggerFactory loggerFactory, string sourceName, LogManager pa //} /// - /// Implements the finalizer. Calls Dispose with false. + /// Implements the deconstructor. Calls Dispose with false. /// ~LogManager() { @@ -161,6 +161,45 @@ public virtual void Dispose() #region Public Methods + /// + /// Adds parameters to + /// + /// + /// + [Obsolete("Use AddAdditionalParams(string paramName, string paramValue) instead.")] + public void AddScope(string scopeName, string scopeValue) + { + this.AddAdditionalParams(scopeName, scopeValue); + } + + [Obsolete("Use RemoveAdditionalParams(string paramName) instead.")] + public void RemoveScope(string scopeName) + { + this.RemoveAdditionalParams(scopeName); + } + + /// + /// Begins a new Scope on ILogger + /// + /// + /// + /// + public IDisposable BeginScope(TState state) + { + return m_Logger.BeginScope(state); + } + + /// + /// Begins a new Scope on ILogger + /// + /// + /// + /// + public IDisposable BeginScope(string messageFormat, params object[] args) + { + return m_Logger.BeginScope(messageFormat, args); + } + /// /// Closes all resources. /// @@ -173,7 +212,7 @@ public void Close() /// The Method traces a message. /// /// The Trace level for this message. - /// The event id to identifiy a specific event.. + /// The event id to identify a specific event.. /// The message to trace. The message can contains format placeholders, which are /// filled with the parameters. /// The Parameters to fill the message. @@ -187,7 +226,7 @@ public void TraceMessage(TracingLevel traceLevel, int eventId, string msg, param /// /// The Method traces a message. /// - /// The event id to identifiy a specific event.. + /// The event id to identify a specific event.. /// The message to trace. The message can contains format placeholders, which are /// filled with the parameters. /// The Parameters to fill the message. @@ -199,10 +238,10 @@ public void TraceMessage(int eventId, string msg, params object[] myParams) /// - /// The Method traces a error which is occured in the application. + /// The Method traces a error which is occurred in the application. /// /// The Trace level for this message. - /// The event id to identifiy a specific event.. + /// The event id to identify a specific event.. /// The message to trace. The message can contains format placeholders, which are /// filled with the parameters. /// The Parameters to fill the message. @@ -214,9 +253,9 @@ public void TraceError(TracingLevel traceLevel, int eventId, string msg, params } /// - /// The Method traces a error which is occured in the application. + /// The Method traces a error which is occurred in the application. /// - /// The event id to identifiy a specific event.. + /// The event id to identify a specific event.. /// The message to trace. The message can contains format placeholders, which are /// filled with the parameters. /// The Parameters to fill the message. @@ -227,11 +266,11 @@ public void TraceError(int eventId, string msg, params object[] myParams) } /// - /// The Method traces a error which is occured in the application. + /// The Method traces a error which is occurred in the application. /// The Error contain an exception. /// /// The Trace level for this message. - /// The event id to identifiy a specific event.. + /// The event id to identify a specific event.. /// The Error exception. /// The message to trace. The message can contains format placeholders, which are /// filled with the parameters. @@ -244,10 +283,10 @@ public void TraceError(TracingLevel traceLevel, int eventId, Exception err, stri } /// - /// The Method traces a error which is occured in the application. + /// The Method traces a error which is occurred in the application. /// The Error contain an exception. /// - /// The event id to identifiy a specific event.. + /// The event id to identify a specific event.. /// The Error exception. /// The message to trace. The message can contains format placeholders, which are /// filled with the parameters. @@ -259,10 +298,10 @@ public void TraceError(int eventId, Exception err, string msg, params object[] m } /// - /// The Method traces a warning which is occured in the application. + /// The Method traces a warning which is occurred in the application. /// /// The Trace level for this message. - /// The event id to identifiy a specific event.. + /// The event id to identify a specific event.. /// The message to trace. The message can contains format placeholders, which are /// filled with the parameters. /// The Parameters to fill the message. @@ -274,9 +313,9 @@ public void TraceWarning(TracingLevel traceLevel, int eventId, string msg, param } /// - /// The Method traces a warning which is occured in the application. + /// The Method traces a warning which is occurred in the application. /// - /// The event id to identifiy a specific event.. + /// The event id to identify a specific event.. /// The message to trace. The message can contains format placeholders, which are /// filled with the parameters. /// The Parameters to fill the message. @@ -298,7 +337,7 @@ public void TraceDebug(int eventId, string msg, params object[] myParams) } /// - /// The method traces a Criticial message. + /// The method traces a Critical message. /// /// /// @@ -322,8 +361,34 @@ public void TraceCritical(int eventId, Exception err, string msg, params object[ #endregion + #region Protected Methods + /// + /// Dispose(bool disposing) executes in two distinct scenarios. + /// If disposing equals true, the method has been called directly + /// or indirectly by a user's code. Managed and unmanaged resources + /// can be disposed. + /// If disposing equals false, the method has been called by the + /// runtime from inside the finalize and you should not reference + /// other objects. Only unmanaged resources can be disposed. + /// + /// Specifies whether to dispose all managed resources. + /// Override this method by implementing of custom logging. + protected virtual void Dispose(bool disposing) + { + // If disposing equals true, dispose all managed + // and unmanaged resources. + if (disposing) + { + + } + } + + #endregion + + #region Private Methods + /// /// Trace the message in the trace source. /// @@ -392,28 +457,7 @@ private LogLevel mapToLogLevel(TracingLevel traceLevel) return LogLevel.None; } } - - - /// - /// Dispose(bool disposing) executes in two distinct scenarios. - /// If disposing equals true, the method has been called directly - /// or indirectly by a user's code. Managed and unmanaged resources - /// can be disposed. - /// If disposing equals false, the method has been called by the - /// runtime from inside the finalize and you should not reference - /// other objects. Only unmanaged resources can be disposed. - /// - /// Specifies whether to dispose all managed resources. - /// Override this method by implementing of custom logging. - protected virtual void Dispose(bool disposing) - { - // If disposing equals true, dispose all managed - // and unmanaged resources. - if (disposing) - { - - } - } + #endregion #region Scope @@ -454,7 +498,7 @@ public Dictionary CurrentScope } /// - /// Local Scopes List + /// Local AdditionalParameters List /// private Dictionary m_AdditionalParams = new Dictionary(); @@ -462,33 +506,33 @@ public Dictionary CurrentScope private ILogger m_Logger; /// - /// Add a scope + /// Add key/value to additional parameters /// - /// The name of the scope - /// The value of the scope. - public void AddAdditionalParams(string scopeName, string scopeValue) + /// The name of the scope + /// The value of the scope. + public void AddAdditionalParams(string paramName, string paramValue) { lock (m_AdditionalParams) { - if (m_AdditionalParams.ContainsKey(scopeName)) - m_AdditionalParams.Remove(scopeName); - m_AdditionalParams.Add(scopeName, scopeValue); + if (m_AdditionalParams.ContainsKey(paramName)) + m_AdditionalParams.Remove(paramName); + m_AdditionalParams.Add(paramName, paramValue); } } /// - /// Remove a scope + /// Remove key from additional parameters /// - /// The name of the scope - public void RemoveScope(string scopeName) + /// The name of the scope + public void RemoveAdditionalParams(string paramName) { - if (String.IsNullOrEmpty(scopeName)) - throw new ArgumentException("The scope name is null or empty", nameof(scopeName)); + if (String.IsNullOrEmpty(paramName)) + throw new ArgumentException("The scope name is null or empty", nameof(paramName)); lock (m_AdditionalParams) { - if (m_AdditionalParams.ContainsKey(scopeName)) - m_AdditionalParams.Remove(scopeName); + if (m_AdditionalParams.ContainsKey(paramName)) + m_AdditionalParams.Remove(paramName); } } @@ -519,7 +563,6 @@ private void buildScope(Dictionary scopeToFill) } } - #endregion } }