Ejemplo n.º 1
0
        private string GetPath(LogEventTypeEnum evtType, bool isErrorPath)
        {
            string loggerPath;

            if (isErrorPath)
            {
                loggerPath = AppSettingsHelper.GetAppSetting("logger.errorpath", false, @"%appdir\Logs\%dat\Errors\Logs.%usr.log");
            }
            else
            {
                loggerPath = AppSettingsHelper.GetAppSetting("logger.path", false, @"%appdir\Logs\%dat\Logs.%usr.log");
            }

            var builder = new StringBuilder(loggerPath);

            builder.Replace("%appdir", AppDomain.CurrentDomain.BaseDirectory);
            builder.Replace("%tempdir", Path.GetTempPath());
            builder.Replace("%usr", this.GetValidPathName(System.Threading.Thread.CurrentPrincipal.Identity.Name));
            builder.Replace("%prt", this.GetValidPathName(evtType.ToString()));
            builder.Replace("%dat", this.GetValidPathName(DateTime.Now.ToString("yyyy-MM-dd")));

            if (loggerPath.IndexOf("%host") != -1)
            {
                builder.Replace("%host", this.GetValidPathName(Environment.MachineName));
            }

            builder.Replace("/", @"\");

            return(builder.ToString());
        }
Ejemplo n.º 2
0
        private string ParseMessage(LogEventTypeEnum evtType, string message)
        {
            string className = null;
            bool   flag      = false;

            var builder = new StringBuilder(format);

            builder.Replace("%usr", GetCurrentUsername());
            builder.Replace("%prt", evtType.ToString());
            builder.Replace("%dat", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff"));
            builder.Replace("%msg", message);
            builder.Replace("%tab", "\t");
            builder.Replace("%nln", "\r\n");

            if (format.IndexOf("%host") != -1)
            {
                builder.Replace("%host", Environment.MachineName);
            }

            builder.Replace("%tid", System.Threading.Thread.CurrentThread.ManagedThreadId.ToString());

            if (format.IndexOf("%mtd") != -1)
            {
                className = GetClassName();
                flag      = true;
                builder.Replace("%mtd", className);
            }

            if (format.IndexOf("%cls") != -1)
            {
                if (!flag)
                {
                    className = GetClassName();
                }
                builder.Replace("%cls", className);
            }

            return(builder.ToString());
        }