<p>A lot of my C# code follows this pattern:</p>

<pre><code>void foo(string param1, string param2, string param3)
{
    try
    {
         // do something...
    }
    catch(Exception ex)
    {
        LogError(String.Format("Error in foo(param1={0}, param2={1}, param3={2}), exception={3}", param1, param2, param3, ex.Message));
    }
}
</code></pre>

<p>Is there a way in .NET to get a Key/Value list of the parameters to a function so that I can call another function to construct my error logging string?
OR
Do you have a more generic / better way of doing this?</p>

When I have done this I just created a generic dictionary for the logging.
I have this LogArgs class.  And logging in a base class that I call when I have an exception.
```
```
public class LogArgs
{

    public string MethodName { get; set; }
    public string ClassName { get; set; }
    public Dictionary<string, object> Paramters { get; set; }

    public LogArgs()
    {
        this.Paramters = new Dictionary<string, object>();
    }

}
```
```
Then at the start of every method I do
```
```
LogArgs args = new LogArgs { ClassName = "ClassName", MethodName = "MethodName" };
args.Paramters.Add("Param1", param1);
args.Paramters.Add("Param2", param2);
args.Paramters.Add("Param3", param3);

base.Logger.MethodStartLog(args);
```
```
When I have an error I log it this way.
```
```
base.Logger.LogError(args, ex);
```
```