Exemplo n.º 1
0
        public IGoogleLogger ForType(Type type)
        {
            GoogleLogger retVal = new GoogleLogger();

            Log.Debug("GAPI{0}={1}.", retVal.m_id,
                      type.FullName);
            return(retVal);
        }
Exemplo n.º 2
0
 internal static void Register()
 {
     try
     {
         GoogleLogger glogger = new GoogleLogger();
         Google.ApplicationContext.RegisterLogger(glogger);
         Log.Debug("Google logging registered.");
     }
     catch (InvalidOperationException e)
     {
         Log.Warning("Google API logging not available:",
                     e.Message);
     }
 }
Exemplo n.º 3
0
        public static void Configure()
        {
            // temprorary; replace with UI model.
            NameValueCollection appSettings
                = ConfigurationManager.AppSettings;
            string strLevel = appSettings["KpSyncLogLevel"];

            if (string.IsNullOrEmpty(strLevel))
            {
                strLevel = Enum.GetName(typeof(LogEventLevel),
                                        LogEventLevel.Debug);
            }
            LogEventLevel level;

            if (!Enum.TryParse(strLevel, out level))
            {
                uint intLevel;
                if (uint.TryParse(strLevel, out intLevel))
                {
                    intLevel = Math.Min(intLevel, (uint)LogEventLevel.Fatal);
                    level    = (LogEventLevel)intLevel;
                }
                else
                {
                    level = LogEventLevel.Debug;
                }
            }
            string strFilePath = appSettings["KpSyncLogFile"];

            if (string.IsNullOrEmpty(strFilePath) ||
                Path.GetInvalidPathChars()
                .Any(c => strFilePath.Contains(c)) ||
                !Path.IsPathRooted(strFilePath))
            {
                return;
            }

            try
            {
                LoggerConfiguration logConfig = new LoggerConfiguration();
                logConfig = logConfig.WriteTo.File(strFilePath,
                                                   rollingInterval: RollingInterval.Day,
                                                   retainedFileCountLimit: 20);
                s_logger = logConfig.MinimumLevel.Is(level)
                           .CreateLogger();
                GoogleLogger.Register();

                Assembly asm = Assembly.GetExecutingAssembly();
                Info("{0} v{1} loaded by {2} v{3}.",
                     GdsDefs.ProductName, asm.GetName().Version,
                     PwDefs.ShortProductName, PwDefs.VersionString);
                TargetFrameworkAttribute attr
                    = asm.GetCustomAttribute <TargetFrameworkAttribute>();
                string tgtFw = attr == null ? "(unknown)" :
                               attr.FrameworkDisplayName;
                Info("Target={0}, Current CLR=v{1}",
                     tgtFw, Environment.Version);
                string releaseId = TryGetRegValueAsString(
                    @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion",
                    "ReleaseId", "<unknown>");
                string edition = TryGetRegValueAsString(
                    @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion",
                    "ProductName", "Windows ??");
                Info("OS Product: {0}, {1}", edition, releaseId);
                OperatingSystem os = Environment.OSVersion;
                Info("Platform ID: {0:G}, {1}, SP('{2}')",
                     os.Platform, os.VersionString, os.ServicePack);
                Info("Installed .NET Framework: {0}", GetNetFrameworkVer());
            }
            catch (Exception e)
            {
                Error(e, "Logging setup exception.");
            }
        }