本文整理汇总了C#中System.Diagnostics.StackFrame类的典型用法代码示例。如果您正苦于以下问题:C# StackFrame类的具体用法?C# StackFrame怎么用?C# StackFrame使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StackFrame类属于System.Diagnostics命名空间,在下文中一共展示了StackFrame类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PromoteException
//Can only be called inside a service
public static void PromoteException(Exception error,MessageVersion version,ref Message fault)
{
StackFrame frame = new StackFrame(1);
Type serviceType = frame.GetMethod().ReflectedType;
PromoteException(serviceType,error,version,ref fault);
}
示例2: OnAuthentication
public void OnAuthentication(AuthenticationContext filterContext)
{
System.Diagnostics.StackFrame stackFrame = new System.Diagnostics.StackFrame();
System.Reflection.MethodBase methodBase = stackFrame.GetMethod();
log.Debug("Start: " + methodBase.Name);
try
{
if (UserLogin.ValidateUserRequest())
{
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "controller", "Home" }, { "action", "Login" }, { "area", "" } });
}
else
{
string context = filterContext.Controller.ControllerContext.HttpContext.Request.Path;
int UserID = Convert.ToInt32(filterContext.HttpContext.Session["UserID"]);
string Role = MenuBinding.CheckURlAndGetUserRole(context, UserID);
if (Role == null)
{
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "controller", "Home" }, { "action", "Index" }, { "area", "" } });
}
filterContext.Controller.ViewBag.Role = Role;
}
}
catch (Exception ex)
{
log.Error("Error: " + ex);
}
log.Debug("End: " + methodBase.Name);
}
示例3: GetCurrentClassLogger
/// <summary>
/// Gets a <see cref="ILog"/> instance named after the caller's declaring or reflected type.
/// </summary>
public static ILog GetCurrentClassLogger()
{
var caller = new StackFrame(1, false).GetMethod();
var name = (caller.DeclaringType ?? caller.ReflectedType ?? typeof(UnknownLogger)).FullName;
return Instance.CreateLogger(name);
}
示例4: Include
public override bool Include(StackFrame frame)
{
var method = frame.GetMethod();
if (IsHiddenMember(method))
{
return false;
}
var type = method.DeclaringType;
// TODO (https://github.com/dotnet/roslyn/issues/5250): look for other types indicating that we're in Roslyn code
if (type == typeof(CommandLineRunner))
{
return false;
}
// Type is null for DynamicMethods and global methods.
// TODO (tomat): we don't want to include awaiter helpers, shouldn't they be marked by DebuggerHidden in FX?
if (type == null || IsTaskAwaiter(type) || IsTaskAwaiter(type.DeclaringType))
{
return false;
}
return true;
}
示例5: GetClassFullName
// Copied from NLog
static string GetClassFullName()
{
string className;
Type declaringType;
int framesToSkip = 2;
do {
#if SILVERLIGHT
StackFrame frame = new StackTrace().GetFrame(framesToSkip);
#else
StackFrame frame = new StackFrame(framesToSkip, false);
#endif
MethodBase method = frame.GetMethod();
declaringType = method.DeclaringType;
if (declaringType == null) {
className = method.Name;
break;
}
framesToSkip++;
className = declaringType.FullName;
} while (declaringType.Module.Name.Equals("mscorlib.dll", StringComparison.OrdinalIgnoreCase));
return className;
}
示例6: Log
private static void Log(LogLevel logLevel, string msg)
{
if (logLevel < LogLevel) return;
StackFrame frame = new StackFrame(2, true);
var method = frame.GetMethod();
var lineNumber = frame.GetFileLineNumber();
var color = Console.ForegroundColor;
switch (logLevel)
{
case LogLevel.None:
break;
case LogLevel.Debug:
Console.ForegroundColor = ConsoleColor.DarkGray;
break;
case LogLevel.Info:
Console.ForegroundColor = ConsoleColor.Gray;
break;
case LogLevel.Warning:
Console.ForegroundColor = ConsoleColor.Yellow;
break;
case LogLevel.Error:
Console.ForegroundColor = ConsoleColor.Red;
break;
}
Console.WriteLine("{0}.{1}:{2} - {3}", method.DeclaringType.FullName, method.Name, lineNumber, msg);
Console.ForegroundColor = color;
}
示例7: Enrich
public void Enrich(LogEvent e, out string propertyName, out object propertyValue)
{
var frame = new StackFrame(4); //warning! this can change after refactoring
propertyName = "method";
MethodBase method = frame.GetMethod();
var sb = new StringBuilder();
sb.Append(method.DeclaringType.FullName);
sb.Append(".");
sb.Append(method.Name);
sb.Append("(");
bool isFirst = true;
foreach(ParameterInfo p in method.GetParameters())
{
if (!isFirst)
{
sb.Append(", ");
}
else
{
isFirst = false;
}
sb.Append(p.ParameterType.Name);
sb.Append(" ");
sb.Append(p.Name);
}
sb.Append(")");
propertyValue = sb.ToString();
}
示例8: GetClassLogger
public static ScopeLogger GetClassLogger(ILogTape baseLogger = null, int framesToSkip = 1)
{
// extracted from: https://github.com/NLog
string loggerName;
Type declaringType;
do
{
StackFrame frame = new StackFrame(framesToSkip, false);
var method = frame.GetMethod();
declaringType = method.DeclaringType;
if (declaringType == null)
{
loggerName = method.Name;
break;
}
framesToSkip++;
loggerName = declaringType.FullName;
} while (declaringType.Module.Name.Equals("mscorlib.dll", StringComparison.OrdinalIgnoreCase));
if (baseLogger == null)
baseLogger = commonLogTape;
return new ScopeLogger(loggerName, baseLogger);
}
示例9: HandleException
public static void HandleException(Exception ex, string msg)
{
try
{
if (_exceptionUseReflection)
{
var frame = new StackFrame(1);
frame.GetMethod();
}
if (ex.InnerException != null)
{
}
if (!string.IsNullOrEmpty(msg))
{
msg = "**************" + msg + "**************" + Environment.NewLine;
}
else
{
msg = Environment.NewLine;
}
var message = (_exceptionRecurseError) ? msg + RecurseErrorStack(ex) : msg;
if (message.Length > 0)
{
Ea.GetEvent<DisplayExceptionMessage>().Publish(message);
Ea.GetEvent<HideBusyIndicator>().Publish(string.Empty);
}
}
catch (Exception iex)
{
throw (new Exception("Exception in HandleException(Exception ex, string msg): " + iex.Message));
}
}
示例10: GetWebRootFileSystemDirectory
public static string GetWebRootFileSystemDirectory(string debugPath = null)
{
string fileSystemWebRoot = null;
try
{
if (!string.IsNullOrEmpty(debugPath))
{
var sf = new StackFrame(0, true);
var fileName = sf.GetFileName();
var sourceWebRootDirectory = string.IsNullOrEmpty(fileName)
? ""
: Path.GetFullPath(Path.Combine(fileName, @"..\..\..", debugPath));
fileSystemWebRoot = Directory.Exists(sourceWebRootDirectory)
? sourceWebRootDirectory
: AppDomain.CurrentDomain.BaseDirectory;
}
else
{
fileSystemWebRoot = AppDomain.CurrentDomain.BaseDirectory;
}
}
catch (Exception)
{
fileSystemWebRoot = AppDomain.CurrentDomain.BaseDirectory;
}
return fileSystemWebRoot;
}
示例11: GetCurrentClassLogger
/// <summary>
/// 获取日志记录器(为当前类找出匹配的日志记录器)
/// </summary>
public ILogger GetCurrentClassLogger()
{
var frame = new StackFrame(2); //调用日志记录器的类所在的堆栈帧
Type classType = frame.GetMethod().ReflectedType;
// 查找配置中所有匹配的日志记录器
IList<ILogger> loggers = FindLoggers(classType);
if (loggers.Count == 0)
{
return LogManager.NullLogger;
}
if (loggers.Count == 1)
return loggers[0];
MultiLogger logger = new MultiLogger(loggers);
LogLevel minLevel = LogLevel.Fatal;
foreach (var logger1 in loggers)
{
if (logger1.MinLevel < minLevel)
minLevel = logger1.MinLevel;
}
logger.LoadConfig(new LoggerConfig{MinLevel = minLevel, Name = "MultiLogger"});
return logger;
}
示例12: LogData
internal LogData (LogLevel level, StackFrame caller, string message)
{
_level = level;
_caller = caller;
_message = message ?? String.Empty;
_date = DateTime.Now;
}
示例13: Log
public static void Log(string message)
{
var trace = new StackFrame(1);
var methodBase = trace.GetMethod();
var type = methodBase.DeclaringType;
LogManager.GetLogger(type).Info(message);
}
示例14: GetCallingType
public static Type GetCallingType()
{
if (EnvironmentHelper.IsProcessHostedByTool)
{
return typeof(object);
}
//#if NETFX_CORE
// var type = typeof(object);
//#else
// var stackTrace = StackTraceHelper.GetStackTrace();
// var stackFrame = stackTrace.GetFrame(2);
// var type = stackFrame.GetMethod().DeclaringType;
//#endif
#if NET
var frame = new StackFrame(2, false);
var type = frame.GetMethod().DeclaringType;
#elif NETFX_CORE
var type = typeof(object);
#else
var frame = new StackTrace().GetFrame(2);
var type = frame.GetMethod().DeclaringType;
#endif
return type;
}
示例15: GetLastLogin
public string GetLastLogin(string id)
{
var s = "";
try
{
var query = string.Format("SELECT * from WP_GAA_Users where Unique_ID like '{0}';", id);
using (var connection = new MySqlConnection(ConnectionString))
{
connection.Open();
using (var cmd = new MySqlCommand(query, connection))
{
using (var r = cmd.ExecuteReader())
{
while (r.Read())
{
var loginOrdinal = r.GetOrdinal("Last_Used");
if (r.IsDBNull(loginOrdinal)) s = DateTime.MinValue.ToString();
else s = r.GetString("Last_Used");
}
}
}
}
}
catch (Exception ex)
{
var sf = new StackFrame();
var methodBase = sf.GetMethod();
Database.InsertErrorToDb(methodBase.Name, ex.Message, ex.ToString());
}
return s;
}