0

我使用这段代码:

 MethodInvoker TileLoadCompleteMethodInvoker = delegate()
{
    CleanStatusLabelTimer.Enabled = true;
    MemoryTextBox.Text = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0:0.00} MB of {1:0.00} MB", MainMapControl.Manager.MemoryCache.Size, MainMapControl.Manager.MemoryCache.Capacity);
};
try
{
    BeginInvoke(TileLoadCompleteMethodInvoker);
}
catch (TargetInvocationException ex)
{
    BLL.FunctionsClass.LogExceptions(ex.InnerException);
}

LogExceptions 方法在这里:

    public class LogExceptions
{
public static void WriteLogException(Exception exMsg)
{
    string filePath = Application.StartupPath + "\\ExceptionLog.log";
    using (System.IO.StreamWriter file = new System.IO.StreamWriter(filePath, true))
    {
        file.WriteLine("-------------------Exception Begin----------------------");
        file.WriteLine(string.Format("Date: {0}, Time: {1}", DateTime.Now.ToShortTimeString()));
        file.WriteLine(string.Format("Exception Message: {0}", exMsg.ToString()));
        file.WriteLine(string.Format("Source: {0}", exMsg.Source));
        file.WriteLine("-------------------Exception End----------------------");
        file.WriteLine();
    }
}
}

此方法将异常保存在日志文件中。但是调用 LogExceptions 方法时发生此错误; 不可调用的成员 'IslamAtlas.BLL.FunctionsClass.LogExceptions' 不能像方法一样使用。 我怎样才能解决这个问题?谢谢。

4

2 回答 2

1

您正在调用类,而不是方法!
改用这个:

BLL.FunctionsClass.LogExceptions.WriteLogException(ex.InnerException);

更多:这里还有另一个错误:

string.Format("Date: {0}, Time: {1}", DateTime.Now.ToShortTimeString()

String.Format用两个参数调用,但只传递一个!

越来越多:这条线

string.Format("Exception Message: {0}", exMsg.ToString())

应该在我看来

string.Format("Exception Message: {0}", exMsg.Message)
于 2012-06-18T09:52:48.567 回答
0

你有这样的称呼:

BLL.FunctionsClass.LogExceptions.WriteLogException(ex.InnerException);
于 2012-06-18T09:52:38.440 回答