You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.2 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Configuration;
using Database;
using System.Net.Http;
using System.ComponentModel;
namespace API_NetFramework.Models
{
public enum LogLevelType { Info, Warning, Trace, Debug, Error }
public static class APILogging
{
public static void initLogging()
{
if (Logging.Logging.IntLogLevel == "")
{
string connectionstring = ConfigurationManager.ConnectionStrings["EDOKAConnectionstring"].ConnectionString;
DB db = new DB(connectionstring);
db.Get_Tabledata("Select * from nlog_parameter where id=3", false, true);
Logging.Logging.IntLogLevel = db.dsdaten.Tables[0].Rows[0]["LogLevel"].ToString();
Logging.Logging.IntUserID = db.dsdaten.Tables[0].Rows[0]["LogUserID"].ToString();
db = null;
}
}
public static void Log(HttpRequestMessage request, string Message, LogLevelType logtype)
{
string userhost = "";
if (request.Properties.ContainsKey("MS_HttpContext"))
{
userhost = ((HttpContextWrapper)request.Properties["MS_HttpContext"]).Request.UserHostAddress;
}
switch (logtype)
{
case LogLevelType.Info:
Logging.Logging.Info(Message, request.RequestUri.ToString(), userhost);
break;
case LogLevelType.Warning:
Logging.Logging.Warning(Message, request.RequestUri.ToString(), userhost);
break;
case LogLevelType.Trace:
Logging.Logging.Trance(Message, request.RequestUri.ToString(), userhost);
break;
case LogLevelType.Debug:
Logging.Logging.Debug(Message, request.RequestUri.ToString(), userhost);
break;
case LogLevelType.Error:
Logging.Logging.Error(Message, request.RequestUri.ToString(), userhost);
break;
default:
break;
}
}
}
}