调试实时ASP.net网站

时间:2017-01-20 12:04:23

标签: c# asp.net .net debugging

我有一个C#ASP.net网站。在本地我可以在调试中运行它并逐步执行代码以查看为什么事情无法正常工作,但当它在我的实时网站上托管时我无法做到这一点。

调试我网站上发生的事情的最佳方法是什么?

我应该添加debut / output / trace语句吗?

如果是,我该如何查看这些的输出?我可以在Chrome浏览器中查看它们吗?>以某种方式开发者工具?

例如,现在我可以在我的网站上注册用户,因此我知道数据库连接是好的,但我无法登录注册用户并且想知道原因。

由于

3 个答案:

答案 0 :(得分:1)

您可以在应用上添加跟踪和调试日志。为方便起见,您可以使用类似的日志框架 http://nlog-project.org/ https://serilog.net/

答案 1 :(得分:1)

您实际上可以编写自己的日志记录机制,您可以在其中创建日志类及其中的一些功能,例如

 public class Log
    {

        internal static bool RecordLog(string strSource, string strMethodName, string strStatement)//additional params you think appropriate for your logs
        {


                List<string> lstInfo = new List<string>();

                string strProductName = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location.ToString()).ProductName.ToString();
                string strProductVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location.ToString()).ProductVersion.ToString();

                try
                {
                    strProductName = FileVersionInfo.GetVersionInfo(Assembly.GetCallingAssembly().Location.ToString()).ProductName.ToString();
                    strProductVersion = FileVersionInfo.GetVersionInfo(Assembly.GetCallingAssembly().Location.ToString()).ProductVersion.ToString();
                }
                catch
                {
                }

                try
                {
                    lstInfo.Add("** Date=" + DateTime.Now.ToString("d MMM yy, H:mm:ss") + ", " + strProductName + " v" + strProductVersion);
                    lstInfo.Add("Source=" + strSource + ", Server=" + strServerIP + ""); //add more info in list as per rquirement                  

                    bool flag = blnWriteLog("LogFilename",  lstInfo);
                }
                catch (Exception objEx)
                {
                 //exception handling 
                }

            return true;
        }

        private static bool blnWriteLog(string strProductName,  List<string> lstInfo)
        {
            string strPath = strGetLogFileName(strProductName);
            using StreamReader write in the log file received 

            return true;
        }

        private static string strGetLogFileName(string strFilePrefix)
        {
            //logic to check your file name, if it exists return name else create one 

            return strFile;

        }
    }

然后您可以在文件中使用相同的文件

Log.RecordLog()// Values as per your code and requirement 

注意:上面只是建议的方法,还可以有许多其他有效的方法

答案 2 :(得分:1)

您可以使用内置的Microsoft Intellitrace功能逐步执行生成的intellitrace日志中的代码。此链接https://msdn.microsoft.com/en-us/library/dn449058.aspx提供了有关如何实现以下内容的说明;

  

&#34;如果您使用Microsoft Monitoring Agent来控制IntelliTrace,   您还需要设置应用程序性能监视设置   你的网络服务器。这会在您的应用运行时记录诊断事件   并将事件保存到IntelliTrace日志文件中。然后你可以看看   Visual Studio Enterprise中的事件(但不是Professional或   社区版),转到事件发生的代码,看看   在该时间点记录的值,并向前或向前移动   向后浏览运行的代码。找到并修复后   问题,重复循环以构建,发布和监控您的发布   这样您就可以更早,更快地解决未来的潜在问题。&#34;