使用异步

时间:2018-09-14 07:17:22

标签: c# .net asp.net-web-api async-await

我有如下功能将文件写入日志文件:

private async Task<string> GetResponseString(string test)
{        
    var response = await client.PostAsync("https://something/api/apimethod"....);        
    ProcessWrite("C:\\"log.txt","some text to write").Wait();        
}

static Task ProcessWrite(string filePath,string text)
{
    return WriteTextAsync(filepath,text);
}

static async Task WriteTextAsync(string filePath,string text)
{
    byte[] encodedText = Encoding.Unicode.GetBytes(text);

    using (FileStream sourceStream = new FileStream(filePath,
            FileMode.Append, FileAccess.Write, FileShare.ReadWrite,
            bufferSize: 4096, useAsync: true))
    {

            await sourceStream.WriteAsync(encodedText, 0, encodedText.Length);
    };

}

它用于写入文件,当我在Visual Studio中运行时,我能够写入文件,但是当我在IIS Web服务器中部署它时。然后将内容写入文件停止工作。但是也没有例外。

部署后如何使日志写入?

0 个答案:

没有答案