Hello, I am creating a Logger class for my program.
The method that writes to the log file is below:
I want to change this method so that I have to pass only the object to the WriteLog method and it will automatically retrieve the namespace, class name and method name.
I discovered that I can get the namespace and class name by using: object.GetType().FullName, but I still don't know how to get the method name.
OBS: The method name is the name of the method that called the WriteLog method.
So doing this change the WriteLog method would look like this:
Can anyone help me?
Thanks,
Komyg
The method that writes to the log file is below:
Code:
/// <summary>
/// Logs the input Strings in the following format: "<Namespace>.<Class>.<Method> - Message"
/// </summary>
public void WriteLog(string messageClassFullName, string methodName, string message)
{
if (fileExists && fileOpen)
{
logFile.WriteLine(messageClassFullName + "." + methodName + " - " + message);
logFile.Flush();
}
}
I want to change this method so that I have to pass only the object to the WriteLog method and it will automatically retrieve the namespace, class name and method name.
I discovered that I can get the namespace and class name by using: object.GetType().FullName, but I still don't know how to get the method name.
OBS: The method name is the name of the method that called the WriteLog method.
So doing this change the WriteLog method would look like this:
Code:
/// <summary>
/// Logs the input Strings in the following format: "<Namespace>.<Class>.<Method> - Message"
/// </summary>
public void WriteLog(object obj, string message)
{
if (fileExists && fileOpen)
{
logFile.WriteLine(obj.GetType().FullName + "." + <Someway to get the methodName> + " - " + message);
logFile.Flush();
}
}
Can anyone help me?
Thanks,
Komyg