using params problem
-
i have 2 functions: void Log(LogTypes type, string message, string context); void Log(LogTypes type, string message, params object[] parameters); when i use the following call: Logger.Log(LogTypes.Message, "{0} test", "ddd"); // the "{0}" will be // replaced by "ddd" in format message i get to a problem - how can i force the usage of either one of the functions in the call (for example - one time i want "ddd" to be a context and in another - be a parameter) Any ideas? Thanks.
-
i have 2 functions: void Log(LogTypes type, string message, string context); void Log(LogTypes type, string message, params object[] parameters); when i use the following call: Logger.Log(LogTypes.Message, "{0} test", "ddd"); // the "{0}" will be // replaced by "ddd" in format message i get to a problem - how can i force the usage of either one of the functions in the call (for example - one time i want "ddd" to be a context and in another - be a parameter) Any ideas? Thanks.
The easiest way I can think of is make Context a class called "LogContext". It could be as simple as a wrapper around a string, but at least it differentiates it from a string parameter used in the params argument. One other point, in the naming of your enum. Enums should be singular tense, unless it can be used in a bitmasked way (ie/ are marked with the FlagsAttribute). so for example, LogType.Message <-- singlular as you can only use one at a time UserGroups.User | UserGroups.Administrator <-- example of bitmasked enums
-
The easiest way I can think of is make Context a class called "LogContext". It could be as simple as a wrapper around a string, but at least it differentiates it from a string parameter used in the params argument. One other point, in the naming of your enum. Enums should be singular tense, unless it can be used in a bitmasked way (ie/ are marked with the FlagsAttribute). so for example, LogType.Message <-- singlular as you can only use one at a time UserGroups.User | UserGroups.Administrator <-- example of bitmasked enums