Skip to content

Commit

Permalink
add configure method
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-heinz committed Jan 20, 2023
1 parent 1aa9ba9 commit 8050c9c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.0
1.2.1
5 changes: 2 additions & 3 deletions Arrowgene.Logging.Test/LogProviderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ public class LogProviderTest
{
private class TestNsLogger : TestLogger
{
public override void Initialize(string identity, string name, Action<Log> write, object loggerTypeTag,
object identityTag)
public override void Configure(object loggerTypeConfig, object identityConfig)
{
Assert.Equal("Arrowgene.Logging.Test", identityTag);
Assert.Equal("Arrowgene.Logging.Test", identityConfig);
}
}

Expand Down
8 changes: 7 additions & 1 deletion Arrowgene.Logging.Test/TestLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@ namespace Arrowgene.Logging.Test;

public class TestLogger : ILogger
{
public virtual void Initialize(string identity, string name, Action<Log> write, object loggerTypeTag, object identityTag)
public void Initialize(string identity, string name, Action<Log> write)
{

}

public virtual void Configure(object loggerTypeConfig, object identityConfig)
{

}

public virtual void Write(LogLevel logLevel, string message, object tag)
Expand Down
8 changes: 2 additions & 6 deletions Arrowgene.Logging/ILogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ namespace Arrowgene.Logging
{
public interface ILogger
{
void Initialize(string identity,
string name, Action<Log> write,
object loggerTypeTag,
object identityTag
);

void Initialize(string identity, string name, Action<Log> write);
void Configure(object loggerTypeConfig, object identityConfig);
void Write(LogLevel logLevel, string message, object tag);
void Trace(string message);
void Info(string message);
Expand Down
17 changes: 9 additions & 8 deletions Arrowgene.Logging/LogProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,20 @@ public static ILogger Logger(Type type)
{
if (!Loggers.TryGetValue(identity, out logger))
{
object loggerTypeTag = null;
object loggerTypeConfig = null;
string loggerTypeName = typeof(T).FullName;
if (loggerTypeName != null && LoggerTypeConfigurations.ContainsKey(loggerTypeName))
{
loggerTypeTag = LoggerTypeConfigurations[loggerTypeName];
loggerTypeConfig = LoggerTypeConfigurations[loggerTypeName];
}

object identityTag = null;
object identityConfig = null;
string searchNs = identity;
while (true)
{
if (NamespaceConfigurations.ContainsKey(searchNs))
{
identityTag = NamespaceConfigurations[searchNs];
identityConfig = NamespaceConfigurations[searchNs];
break;
}
int lastIdx = searchNs.LastIndexOf('.');
Expand All @@ -124,7 +124,8 @@ public static ILogger Logger(Type type)
}

logger = new T();
logger.Initialize(identity, name, Write, loggerTypeTag, identityTag);
logger.Initialize(identity, name, Write);
logger.Configure(loggerTypeConfig, identityConfig);
Loggers.Add(identity, logger);
}
}
Expand All @@ -141,7 +142,7 @@ public static ILogger Logger(Type type)
/// <summary>
/// Provide a configuration object that will be passed to every <see cref="ILogger"/> instance
/// that is created and inside the provided namespace
/// by calling <see cref="ILogger.Initialize(string,string,System.Action{Arrowgene.Logging.Log},object,object)"/> on it.
/// by calling <see cref="ILogger.Initialize(string,string,System.Action{Arrowgene.Logging.Log})"/> on it.
/// </summary>
public static void ConfigureNamespace(string ns, object configuration)
{
Expand All @@ -155,7 +156,7 @@ public static void ConfigureNamespace(string ns, object configuration)

/// <summary>
/// Provide a configuration object that will be passed to every <see cref="ILogger"/> instance
/// by calling <see cref="ILogger.Initialize(string,string,System.Action{Arrowgene.Logging.Log},object,object)"/> on it.
/// by calling <see cref="ILogger.Initialize(string,string,System.Action{Arrowgene.Logging.Log})"/> on it.
/// </summary>
public static void Configure<T>(object configuration) where T : ILogger, new()
{
Expand All @@ -169,7 +170,7 @@ public static void Configure(Type type, object configuration)

/// <summary>
/// Provide a configuration object that will be passed to every <see cref="ILogger"/> instance
/// by calling <see cref="ILogger.Initialize(string,string,System.Action{Arrowgene.Logging.Log},object, object)"/> on it.
/// by calling <see cref="ILogger.Initialize(string,string,System.Action{Arrowgene.Logging.Log})"/> on it.
/// </summary>
public static void Configure(string identity, object configuration)
{
Expand Down
12 changes: 9 additions & 3 deletions Arrowgene.Logging/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ public class Logger : ILogger

public virtual void Initialize(string identity,
string name,
Action<Log> write,
object loggerTypeTag,
object identityTag
Action<Log> write
)
{
_identity = identity;
_name = name;
_write = write;
}

public virtual void Configure(
object loggerTypeConfig,
object identityConfig
)
{

}

public void Write(Log log)
{
Expand Down

0 comments on commit 8050c9c

Please sign in to comment.