Call a method from Static Class passing Type of Dynamic variable with Generics?

I want to call LogInfo like this: Log. LogInfo("Some String") Why? Why don't you just do this: public static class Log { private static readonly Dictionary loggers = new Dictionary(); public static void LogInfo(Type type, string message) { var logger = Log.

GetLoggerForType(type); logger. Info(message); } public static void LogInfo(string message) { LogInfo(typeof(T), message); } private static ILog GetLoggerForType(Type type) { ILog logger; if(!loggers. TryGetValue(type, out logger)) { logger = LogManager.

GetLogger(type); loggers. Add(type, logger); } return logger; } } Note that this is not, Not, NOT thread safe. I wanted to communicate the idea Then: Log.

LogInfo("Some String") can be replaced by Log. LogInfo(myObject.GetType(), "Some String") or you can even go one step further and add an overload that allows you to say Log. LogInfo(myObject, "Some String") (just call object.

GetType in LogInfo ).

I want to call LogInfo like this: Log. LogInfo("Some String"); Why? Why don't you just do this: public static class Log { private static readonly Dictionary loggers = new Dictionary(); public static void LogInfo(Type type, string message) { var logger = Log.

GetLoggerForType(type); logger. Info(message); } public static void LogInfo(string message) { LogInfo(typeof(T), message); } private static ILog GetLoggerForType(Type type) { ILog logger; if(!loggers. TryGetValue(type, out logger)) { logger = LogManager.

GetLogger(type); loggers. Add(type, logger); } return logger; } } Note that this is not, Not, NOT thread safe. I wanted to communicate the idea.

Then: Log. LogInfo("Some String"); can be replaced by Log. LogInfo(myObject.GetType(), "Some String"); or you can even go one step further and add an overload that allows you to say Log.

LogInfo(myObject, "Some String"); (just call object. GetType in LogInfo).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions