Skip to content

Commit

Permalink
fix naming of Scope/AdditionalParams methods
Browse files Browse the repository at this point in the history
  • Loading branch information
hvetter-de committed Sep 19, 2017
1 parent 3964197 commit 3c42d0d
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 55 deletions.
12 changes: 11 additions & 1 deletion Daenet.Common.Logging/ILogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,27 @@ public interface ILogManager
Dictionary<string, string> 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>(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);
}
}
151 changes: 97 additions & 54 deletions Daenet.Common.Logging/LogManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public LogManager(ILoggerFactory loggerFactory, string sourceName, LogManager pa
//}

/// <summary>
/// Implements the finalizer. Calls Dispose with false.
/// Implements the deconstructor. Calls Dispose with false.
/// </summary>
~LogManager()
{
Expand All @@ -161,6 +161,45 @@ public virtual void Dispose()

#region Public Methods

/// <summary>
/// Adds parameters to
/// </summary>
/// <param name="scopeName"></param>
/// <param name="scopeValue"></param>
[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);
}

/// <summary>
/// Begins a new Scope on ILogger
/// </summary>
/// <typeparam name="TState"></typeparam>
/// <param name="state"></param>
/// <returns></returns>
public IDisposable BeginScope<TState>(TState state)
{
return m_Logger.BeginScope<TState>(state);
}

/// <summary>
/// Begins a new Scope on ILogger
/// </summary>
/// <param name="messageFormat"></param>
/// <param name="args"></param>
/// <returns></returns>
public IDisposable BeginScope(string messageFormat, params object[] args)
{
return m_Logger.BeginScope(messageFormat, args);
}

/// <summary>
/// Closes all resources.
/// </summary>
Expand All @@ -173,7 +212,7 @@ public void Close()
/// The Method traces a message.
/// </summary>
/// <param name="traceLevel">The Trace level for this message.</param>
/// <param name="eventId">The event id to identifiy a specific event..</param>
/// <param name="eventId">The event id to identify a specific event..</param>
/// <param name="msg">The message to trace. The message can contains format placeholders, which are
/// filled with the parameters.</param>
/// <param name="myParams">The Parameters to fill the message.</param>
Expand All @@ -187,7 +226,7 @@ public void TraceMessage(TracingLevel traceLevel, int eventId, string msg, param
/// <summary>
/// The Method traces a message.
/// </summary>
/// <param name="eventId">The event id to identifiy a specific event..</param>
/// <param name="eventId">The event id to identify a specific event..</param>
/// <param name="msg">The message to trace. The message can contains format placeholders, which are
/// filled with the parameters.</param>
/// <param name="myParams">The Parameters to fill the message.</param>
Expand All @@ -199,10 +238,10 @@ public void TraceMessage(int eventId, string msg, params object[] myParams)


/// <summary>
/// The Method traces a error which is occured in the application.
/// The Method traces a error which is occurred in the application.
/// </summary>
/// <param name="traceLevel">The Trace level for this message.</param>
/// <param name="eventId">The event id to identifiy a specific event..</param>
/// <param name="eventId">The event id to identify a specific event..</param>
/// <param name="msg">The message to trace. The message can contains format placeholders, which are
/// filled with the parameters.</param>
/// <param name="myParams">The Parameters to fill the message.</param>
Expand All @@ -214,9 +253,9 @@ public void TraceError(TracingLevel traceLevel, int eventId, string msg, params
}

/// <summary>
/// The Method traces a error which is occured in the application.
/// The Method traces a error which is occurred in the application.
/// </summary>
/// <param name="eventId">The event id to identifiy a specific event..</param>
/// <param name="eventId">The event id to identify a specific event..</param>
/// <param name="msg">The message to trace. The message can contains format placeholders, which are
/// filled with the parameters.</param>
/// <param name="myParams">The Parameters to fill the message.</param>
Expand All @@ -227,11 +266,11 @@ public void TraceError(int eventId, string msg, params object[] myParams)
}

/// <summary>
/// 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.
/// </summary>
/// <param name="traceLevel">The Trace level for this message.</param>
/// <param name="eventId">The event id to identifiy a specific event..</param>
/// <param name="eventId">The event id to identify a specific event..</param>
/// <param name="err">The Error exception.</param>
/// <param name="msg">The message to trace. The message can contains format placeholders, which are
/// filled with the parameters.</param>
Expand All @@ -244,10 +283,10 @@ public void TraceError(TracingLevel traceLevel, int eventId, Exception err, stri
}

/// <summary>
/// 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.
/// </summary>
/// <param name="eventId">The event id to identifiy a specific event..</param>
/// <param name="eventId">The event id to identify a specific event..</param>
/// <param name="err">The Error exception.</param>
/// <param name="msg">The message to trace. The message can contains format placeholders, which are
/// filled with the parameters.</param>
Expand All @@ -259,10 +298,10 @@ public void TraceError(int eventId, Exception err, string msg, params object[] m
}

/// <summary>
/// The Method traces a warning which is occured in the application.
/// The Method traces a warning which is occurred in the application.
/// </summary>
/// <param name="traceLevel">The Trace level for this message.</param>
/// <param name="eventId">The event id to identifiy a specific event..</param>
/// <param name="eventId">The event id to identify a specific event..</param>
/// <param name="msg">The message to trace. The message can contains format placeholders, which are
/// filled with the parameters.</param>
/// <param name="myParams">The Parameters to fill the message.</param>
Expand All @@ -274,9 +313,9 @@ public void TraceWarning(TracingLevel traceLevel, int eventId, string msg, param
}

/// <summary>
/// The Method traces a warning which is occured in the application.
/// The Method traces a warning which is occurred in the application.
/// </summary>
/// <param name="eventId">The event id to identifiy a specific event..</param>
/// <param name="eventId">The event id to identify a specific event..</param>
/// <param name="msg">The message to trace. The message can contains format placeholders, which are
/// filled with the parameters.</param>
/// <param name="myParams">The Parameters to fill the message.</param>
Expand All @@ -298,7 +337,7 @@ public void TraceDebug(int eventId, string msg, params object[] myParams)
}

/// <summary>
/// The method traces a Criticial message.
/// The method traces a Critical message.
/// </summary>
/// <param name="eventId"></param>
/// <param name="msg"></param>
Expand All @@ -322,8 +361,34 @@ public void TraceCritical(int eventId, Exception err, string msg, params object[

#endregion


#region Protected Methods

/// <summary>
/// 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.
/// </summary>
/// <param name="disposing">Specifies whether to dispose all managed resources.</param>
/// <remarks>Override this method by implementing of custom logging.</remarks>
protected virtual void Dispose(bool disposing)
{
// If disposing equals true, dispose all managed
// and unmanaged resources.
if (disposing)
{

}
}

#endregion

#region Private Methods

/// <summary>
/// Trace the message in the trace source.
/// </summary>
Expand Down Expand Up @@ -392,28 +457,7 @@ private LogLevel mapToLogLevel(TracingLevel traceLevel)
return LogLevel.None;
}
}


/// <summary>
/// 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.
/// </summary>
/// <param name="disposing">Specifies whether to dispose all managed resources.</param>
/// <remarks>Override this method by implementing of custom logging.</remarks>
protected virtual void Dispose(bool disposing)
{
// If disposing equals true, dispose all managed
// and unmanaged resources.
if (disposing)
{

}
}

#endregion

#region Scope
Expand Down Expand Up @@ -454,41 +498,41 @@ public Dictionary<string, string> CurrentScope
}

/// <summary>
/// Local Scopes List
/// Local AdditionalParameters List
/// </summary>
private Dictionary<string, string> m_AdditionalParams = new Dictionary<string, string>();

//private LogManager m_ParentLogMgr;
private ILogger m_Logger;

/// <summary>
/// Add a scope
/// Add key/value to additional parameters
/// </summary>
/// <param name="scopeName">The name of the scope</param>
/// <param name="scopeValue">The value of the scope.</param>
public void AddAdditionalParams(string scopeName, string scopeValue)
/// <param name="paramName">The name of the scope</param>
/// <param name="paramValue">The value of the scope.</param>
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);
}
}

/// <summary>
/// Remove a scope
/// Remove key from additional parameters
/// </summary>
/// <param name="scopeName">The name of the scope</param>
public void RemoveScope(string scopeName)
/// <param name="paramName">The name of the scope</param>
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);
}
}

Expand Down Expand Up @@ -519,7 +563,6 @@ private void buildScope(Dictionary<string, string> scopeToFill)
}
}


#endregion
}
}
Expand Down

0 comments on commit 3c42d0d

Please sign in to comment.