.NET Core 中 HttpContext.Current 的替代方案是什么?
在 .NET Framework 中,此代码如下所示:
ClsLog.WriteLog(HttpContext.Current, GetType(), "GetManualWeightData", ActionType.Action_Read, model.UID, model, clsResponse, clsResponse.ErrorMsg, model.LogCode);
我如何在 .NET Core 中实现这个?
这是我的 ClsLog 代码:
public class ClsLog
{
public static void WriteLog(HttpContext current, Type type, string strMethodName, string strActionType, string strUID, object strParam, object strResponse, string strErrorMsg = "", string strLogCode = "")
{
string strLocalIP = "";
string strBrowser = "";
string strMemID = "";
string strCustomerID = "";
if (current != null)
{
//strLocalIP = current.Session("LocalIP"] + "";
//strBrowser = current.Session["BrowserInfo"] + "";
//strMemID = current.Session["LogID"] + "";
//strCustomerID = current.Session["CustomerID"] + "";
}
try
{
Task.Run(() => ClsWriteLog.getInstance().WriteLogServer(new ClsVariableAppLog("AppAPILog", strLocalIP, strBrowser, strMemID, strCustomerID, type.Module.Name, strMethodName, strUID, strActionType, type.FullName, strErrorMsg, strParam, strResponse, strLogCode)));
//await ClsWriteLog.getInstance().WriteLogServer(new ClsVariableAppLog("AppAPILog", strLocalIP, strBrowser, strMemID, strCustomerID, type.Module.Name, strMethodName, strUID, strActionType, type.FullName, strErrorMsg, strParam, strResponse));
}
catch (Exception ex)
{
Trace.WriteLine("LogError - " + ex.Message);
}
}
}