Esempio n. 1
0
        public string ExceptionInfo(Exception ex, string body)
        {
            //------------------------------------------------------
            // Body
            //------------------------------------------------------
            string s = string.Empty;

            if (!string.IsNullOrEmpty(body))
            {
                s += "<div>" + body + "</div><br /><br />";
            }
            //------------------------------------------------------
            AddStyle(ref s);
            //------------------------------------------------------
            s += "<table border=\"0\" cellspacing=\"2\">";
            var rm = RunMode;

            if (!string.IsNullOrEmpty(rm))
            {
                rm = " (" + rm + ")";
            }
            var asm = System.Reflection.Assembly.GetEntryAssembly();

            if (asm == null)
            {
                Assembly.GetCallingAssembly();
            }
            if (asm == null)
            {
                Assembly.GetExecutingAssembly();
            }
            AddRow(ref s, "Product");
            if (asm != null)
            {
                var ai   = new Configuration.AssemblyInfo(asm);
                var name = ai.Company + " " + ai.Product + " " + ai.Version.ToString(4);
                ApplyRunModeSuffix(ref name);
                AddRow(ref s, "Name", name);
            }
            AddRow(ref s, "Machine", System.Environment.MachineName);
            AddRow(ref s, "Username", System.Environment.UserName);
            if (asm != null)
            {
                var bd = Configuration.AssemblyInfo.GetBuildDateTime(asm.Location);
                AddRow(ref s, "Executable", asm.Location);
                AddRow(ref s, "Build Date", bd.ToString("yyyy-MM-dd HH:mm:ss"));
                //AddRow(ref s, "SVN LastCheckIn", "svn log -q \"%file%\" -r {"+ bd.ToString("yyyy-MM-ddTHH:mm:ss") + "}:{1970-01-01} -l 1");
                //AddRow(ref s, "SVN GetCodeFile", "svn cat -r %rev% \"%file%\" > \"%TEMP%\\code.cs\" && \"%TEMP%\\code.cs\"");

                /* Look for source code in SVN.
                 *
                 * :: Set build date.
                 * set date=2016-10-24T14:12:53
                 * :: Set file name to investigate.
                 * set file=C:\Projects\Volante\Dispatch\Engine\Messages\ClientStateMessage.cs
                 * :: Show last check-in before build (biggest chance of version we are looking for).
                 * svn log -q "%file%" -r {%date%}:{1970-01-01} -l 1
                 * :: Show first check-in after build.
                 * svn log -q "%file%" -r {%date%}:{9999-01-01} -l 1
                 *
                 * :: Save file revision to disk.
                 * svn cat -r r18594 "%file%" > "%TEMP%\svn.cs"
                 * :: Open file with Visual Studio.
                 * "%TEMP%\svn.cs"
                 *
                 */
            }
            // If LogHelper.Web.cs is included
            var methods = new string[] { "UserInfo", "PageInfo" };

            foreach (var method in methods)
            {
                var uiMethod = GetType().GetMethods().FirstOrDefault(x => x.Name == method);
                if (uiMethod != null)
                {
                    var uim  = GetType().GetMethod(method, new Type[] { typeof(string).MakeByRefType() });
                    var args = new object[] { s };
                    uim.Invoke(this, args);
                    s = (string)args[0];
                }
            }
            AddRow(ref s);
            s += "</table>";
            s += "<table border=\"0\" cellspacing=\"2\" class=\"Table\">";
            ExceptionInfoRecursive(ref s, ex);
            //------------------------------------------------------
            s += "</table>";
            return(s);
        }
Esempio n. 2
0
        public string ExceptionInfo(Exception ex, string body, bool addHead = false)
        {
            //------------------------------------------------------
            // Body
            //------------------------------------------------------
            var s = "";

            if (addHead)
            {
                // Wrap into html element and specify UTF-8 encoding.
                s += "<html><head>" +
                     "<meta charset=\"UTF-8\" />" +
                     "<meta name=\"" + XLogHelperErrorSource + "\" content=\"" + ex.Source + "\">" +
                     "<meta name=\"" + XLogHelperErrorType + "\" content=\"" + ex.GetType().FullName + "\">" +
                     "<meta name=\"" + XLogHelperErrorCode + "\" content=\"" + ex.HResult + "\">" +
                     "</head><body>";
            }
            if (!string.IsNullOrEmpty(body))
            {
                s += "<div>" + body + "</div><br /><br />";
            }
            //------------------------------------------------------
            AddStyle(ref s);
            //------------------------------------------------------
            StartTable(ref s);
            var rm = RunMode;

            if (!string.IsNullOrEmpty(rm))
            {
                rm = " (" + rm + ")";
            }
            var asm = System.Reflection.Assembly.GetEntryAssembly();

            if (asm == null)
            {
                Assembly.GetCallingAssembly();
            }
            if (asm == null)
            {
                Assembly.GetExecutingAssembly();
            }
            AddRow(ref s, "Product");
            if (asm != null)
            {
                var ai   = new Configuration.AssemblyInfo(asm);
                var name = ai.Company + " " + ai.Product + " " + ai.Version.ToString(4);
                ApplyRunModeSuffix(ref name);
                AddRow(ref s, "Name", name);
            }
            AddRow(ref s, "Machine", System.Environment.MachineName);
            AddRow(ref s, "Username", System.Environment.UserName);

#if NETSTANDARD  // .NET Standard
#elif NETCOREAPP // .NET Core
#else // .NET Framework
            // Add OS Version.
            //AddRow(ref s, "OS Version", System.Environment.OSVersion.ToString());
            var subKey        = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion";
            var key           = Microsoft.Win32.Registry.LocalMachine;
            var skey          = key.OpenSubKey(subKey);
            var osProductName = skey.GetValue("ProductName").ToString();
            //var osEditionID = skey.GetValue("EditionID").ToString();
            var osReleaseId = skey.GetValue("ReleaseId").ToString();
            var osCurrentMajorVersionNumber = skey.GetValue("CurrentMajorVersionNumber", "").ToString();
            var osCurrentMinorVersionNumber = skey.GetValue("CurrentMinorVersionNumber", "").ToString();
            var osCurrentBuildNumber        = skey.GetValue("CurrentBuildNumber", "").ToString();
            var osUBR = skey.GetValue("UBR", "").ToString();
            skey.Close();
            var osVersion = string.Format("{0} {1} [Version {2}.{3}.{4}.{5}]",
                                          osProductName, osReleaseId,
                                          osCurrentMajorVersionNumber,
                                          osCurrentMinorVersionNumber,
                                          osCurrentBuildNumber,
                                          osUBR
                                          );
            AddRow(ref s, "OS Version", osVersion);
#endif
            if (asm != null)
            {
                var bd = Configuration.AssemblyInfo.GetBuildDateTime(asm.Location);
                AddRow(ref s, "Executable", asm.Location);
                AddRow(ref s, "Build Date", bd.ToString("yyyy-MM-dd HH:mm:ss"));
                //AddRow(ref s, "SVN LastCheckIn", "svn log -q \"%file%\" -r {"+ bd.ToString("yyyy-MM-ddTHH:mm:ss") + "}:{1970-01-01} -l 1");
                //AddRow(ref s, "SVN GetCodeFile", "svn cat -r %rev% \"%file%\" > \"%TEMP%\\code.cs\" && \"%TEMP%\\code.cs\"");

                /* Look for source code in SVN.
                 *
                 * :: Set build date.
                 * set date=2016-10-24T14:12:53
                 * :: Set file name to investigate.
                 * set file=C:\Projects\Volante\Dispatch\Engine\Messages\ClientStateMessage.cs
                 * :: Show last check-in before build (biggest chance of version we are looking for).
                 * svn log -q "%file%" -r {%date%}:{1970-01-01} -l 1
                 * :: Show first check-in after build.
                 * svn log -q "%file%" -r {%date%}:{9999-01-01} -l 1
                 *
                 * :: Save file revision to disk.
                 * svn cat -r r18594 "%file%" > "%TEMP%\svn.cs"
                 * :: Open file with Visual Studio.
                 * "%TEMP%\svn.cs"
                 *
                 */
            }
            // If LogHelper.Web.cs is included
            var methods = new string[] { "UserInfo", "PageInfo" };
            foreach (var method in methods)
            {
                var uiMethod = GetType().GetMethods().FirstOrDefault(x => x.Name == method);
                // If method was found then...
                if (uiMethod != null)
                {
                    // Add rows.
                    var uim  = GetType().GetMethod(method, new Type[] { typeof(string).MakeByRefType() });
                    var args = new object[] { s };
                    uim.Invoke(this, args);
                    s = (string)args[0];
                }
            }
            AddRow(ref s);
            EndTable(ref s);
            StartTable(ref s);
            ExceptionInfoRecursive(ref s, ex);
            EndTable(ref s);
            if (addHead)
            {
                s += "</body></html>";
            }
            return(s);
        }