我在哪里放置代码来记录成功的文件创建?

时间:2013-03-13 17:08:48

标签: c# logging

在下面的代码中,.GenerateFile()返回一个流。这是WCF服务,在给定用户参数的情况下,将文件流回用户的浏览器。 webforms应用程序在浏览器中运行,WCF服务称为服务器端。

问题是,我在哪里放置代码来记录生成文件的成功尝试?如果我将日志代码置于.GenerateFile()调用之上,则无法保证成功。如果成功,则完成此方法(return关键字)。我该怎么办?

    // Other stuff in method
    .
    .
    .
    try
    {
        return this.GenerateFile(xyz1, xyz2);
    }
    catch (Exception ex)
    {
        Msg.SendException(ex);

        Logger.LogException(ex);

        return null;
    }
} // End of Method

1 个答案:

答案 0 :(得分:1)

只需将GenerateFile的结果存储在变量中,记录成功然后返回存储的结果。

try
{
    var result = this.GenerateFile(xyz1, xyz2);
    Log("success");
    return result;
}
相关问题