Esempio n. 1
0
        private static void InitializeFile(HttpContext context)
        {
            lock (StaticSyncRoot)
            {
                if (LoggingThread == null)
                {
                    // Get time:
                    var nowUtc = Current.DateTime.UtcNow;

                    // Create log folder:
                    var path = context.Server.MapPath(ConfigurationManager.AppSettings["W3cLogPath"] ?? "~/App_Data/Logs");
                    Directory.CreateDirectory(path);

                    // Get filename:
                    if (Filename == null)
                    {
                        Filename = Path.Combine(path, String.Format("{0:yyyyMMdd-HHmmss}-{1}-{2}-{3}.log", nowUtc, Environment.MachineName, context.Request.ServerVariables["INSTANCE_ID"], context.Request.ServerVariables["SERVER_NAME"]));
                    }

                    // Create logging thread:
                    LoggingThread = new DedicatedWorkThread <string>(
                        WhenLogHandlerDo,
                        10000,
                        "AsyncLoggingThread");

                    // Connect event handlers:
                    LoggingThread.Reactivate             += WhenLogHandlerReactivate;
                    LoggingThread.Idle                   += WhenLogHandlerIdle;
                    LoggingThread.Failed                 += WhenLogHandlerFailed;
                    AppDomain.CurrentDomain.DomainUnload += WhenAppDomainUnload;
                }
            }
        }
Esempio n. 2
0
        public static void Reset()
        {
            var t = LoggingThread;

            LoggingThread = null;

            if (t != null)
            {
                t.AddWork("#Closing.");
                t.Join();
            }
        }
Esempio n. 3
0
        static LogSystem()
        {
            LoggingKeepAliveTime = TimeSpan.Parse(ConfigurationManager.AppSettings["LoggingKeepAliveTime"] ?? "0");

            LoggingEnabled = Convert.ToBoolean(ConfigurationManager.AppSettings["LoggingEnabled"] ?? "False");

            IsAsynchroneous = Convert.ToBoolean(ConfigurationManager.AppSettings["LoggingAsynchroneous"] ?? "False");

            LogWriter = (ILogWriter)Activator.CreateInstance(Type.GetType(ConfigurationManager.AppSettings["LogWriterType"] /*?? typeof(DefaultLogWriter).AssemblyQualifiedName*/));

            _loggingThread = new DedicatedWorkThread <LogRecord>(
                WhenLogHandlerDo,
                (int)LoggingKeepAliveTime.TotalMilliseconds,
                "AsyncLoggingThread");
            _loggingThread.Idle   += WhenLogHandlerIdle;
            _loggingThread.Failed += WhenLogHandlerFailed;

            AppDomain.CurrentDomain.DomainUnload += WhenAppDomainUnload;
        }
Esempio n. 4
0
        static LogSystem()
        {
            LoggingKeepAliveTime = TimeSpan.Parse(ConfigurationManager.AppSettings["LoggingKeepAliveTime"] ?? "0");

            LoggingEnabled = Convert.ToBoolean(ConfigurationManager.AppSettings["LoggingEnabled"] ?? "False");

            IsAsynchroneous = Convert.ToBoolean(ConfigurationManager.AppSettings["LoggingAsynchroneous"] ?? "False");

            LogWriter = (ILogWriter)Activator.CreateInstance(Type.GetType(ConfigurationManager.AppSettings["LogWriterType"] /*?? typeof(DefaultLogWriter).AssemblyQualifiedName*/));

            _loggingThread = new DedicatedWorkThread<LogRecord>(
                WhenLogHandlerDo,
                (int)LoggingKeepAliveTime.TotalMilliseconds,
                "AsyncLoggingThread");
            _loggingThread.Idle += WhenLogHandlerIdle;
            _loggingThread.Failed += WhenLogHandlerFailed;

            AppDomain.CurrentDomain.DomainUnload += WhenAppDomainUnload;
        }
Esempio n. 5
0
        private static void InitializeFile(HttpContext context)
        {
            lock (StaticSyncRoot)
            {
                if (LoggingThread == null)
                {
                    // Get time:
                    var nowUtc = Current.DateTime.UtcNow;

                    // Create log folder:
                    var path = context.Server.MapPath(ConfigurationManager.AppSettings["W3cLogPath"] ?? "~/App_Data/Logs");
                    Directory.CreateDirectory(path);

                    // Get filename:
                    if (Filename == null)
                    {
                        Filename = Path.Combine(path, String.Format("{0:yyyyMMdd-HHmmss}-{1}-{2}-{3}.log", nowUtc, Environment.MachineName, context.Request.ServerVariables["INSTANCE_ID"], context.Request.ServerVariables["SERVER_NAME"]));
                    }

                    // Retrieve settings:
                    LoggingFlags = (ConfigurationManager.AppSettings["W3cLoggingFlags"] ?? "").Split(',').Select(s => s.Trim().ToLowerInvariant()).ToArray();

                    // Create logging thread:
                    LoggingThread = new DedicatedWorkThread<string>(
                        WhenLogHandlerDo,
                        10000,
                        "AsyncLoggingThread");

                    // Connect event handlers:
                    LoggingThread.Reactivate += WhenLogHandlerReactivate;
                    LoggingThread.Idle += WhenLogHandlerIdle;
                    LoggingThread.Failed += WhenLogHandlerFailed;
                    AppDomain.CurrentDomain.DomainUnload += WhenAppDomainUnload;
                }
            }
        }
Esempio n. 6
0
        public static void Reset()
        {
            var t = LoggingThread;

            LoggingThread = null;

            if (t != null)
            {
                t.AddWork("#Closing.");
                t.Join();
            }
        }