每当调用API时,我都会调用写入日志文件。这在单台机器上完美运行,但只要它被移动到Web场,就什么都不会写。也没有错误。
以下是事情的安排方式
调用API
[HttpGet]
public model.Returns Get([FromUri] model.Requests requests)
使用此函数,Get,是一个写入日志文件的调用,如此
//record request
Task.Run(() => writers.WriteApiLogAsync(requests));
在WriteApiLogAsync中就是这个
logs.Add(new model.Log()
{
Type = requests.t,
When = DateTime.Now,
PhoneId = requests.p,
Location = requests.l,
Phone = requests.ph,
PhoneType = requests.pt
});
//file is locked, attempt write on next round but stack log entries
if (logLocker.IsWriterLockHeld) return;
try
{
var result = await writeLogs(logs);
if(result) logLocker.ReleaseWriterLock();
}
catch (OutOfMemoryException ex)
{
WriteErrorAsnc(ex.Message, ex.ToString(), "WriteApiLogAsync_OutOfMemoryException");
logs.Clear();
logLocker.ReleaseWriterLock();
}
catch (IOException ex)
{
WriteErrorAsnc(ex.Message, ex.ToString(), "WriteApiLogAsync_IOException");
logs.Clear();
logLocker.ReleaseWriterLock();
}
catch (Exception ex)
{
WriteErrorAsnc(ex.Message, ex.ToString(), "WriteApiLogAsync_Exception");
logs.Clear();
logLocker.ReleaseWriterLock();
}
finally
{
if (logs.Count > 1000)
{
logs.Clear();
logLocker.ReleaseWriterLock();
}
}
日志设置为
private static List<model.Log> logs = new List<model.Log>();
我没有指定机器密钥,因为我知道它主要用于加密/解密,而且没有。
任何人都知道原因或者可以指向某个问题相同的地方吗?