You must lock the code portions that access the file. See the
lock Statement (C# Reference)[
^].
Because your logging function is static, you must create a static lock object:
static object lockErrLog = new object();
public static void ErrLog(string filename, string methodname, string errorMsg)
{
lock (lockErrLog)
{
StreamWriter sw = new StreamWriter(strFileName, true);
sw.Close();
}
}