123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Diagnostics;
- namespace SuperSocket.SocketBase.Logging
- {
-
-
-
- public abstract class LogFactoryBase : ILogFactory
- {
-
-
-
- protected string ConfigFile { get; private set; }
-
-
-
- protected bool IsSharedConfig { get; private set; }
-
-
-
-
- protected LogFactoryBase(string configFile)
- {
- if (Path.IsPathRooted(configFile))
- {
- ConfigFile = configFile;
- return;
- }
- if (Path.DirectorySeparatorChar != '\\')
- {
- configFile = Path.GetFileNameWithoutExtension(configFile) + ".unix" + Path.GetExtension(configFile);
- }
- var currentAppDomain = AppDomain.CurrentDomain;
- var isolation = IsolationMode.None;
- var isolationValue = currentAppDomain.GetData(typeof(IsolationMode).Name);
- if (isolationValue != null)
- isolation = (IsolationMode)isolationValue;
- if (isolation == IsolationMode.None)
- {
- var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, configFile);
- if (File.Exists(filePath))
- {
- ConfigFile = filePath;
- return;
- }
- filePath = Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config"), configFile);
- if (File.Exists(filePath))
- {
- ConfigFile = filePath;
- return;
- }
- ConfigFile = configFile;
- return;
- }
- else
- {
-
- var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, configFile);
- if (File.Exists(filePath))
- {
- ConfigFile = filePath;
- return;
- }
-
-
- var rootDir = Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).Parent.FullName;
-
-
- filePath = Path.Combine(rootDir, AppDomain.CurrentDomain.FriendlyName + "." + configFile);
- if (File.Exists(filePath))
- {
- ConfigFile = filePath;
- return;
- }
-
- filePath = Path.Combine(rootDir, configFile);
- if (File.Exists(filePath))
- {
- ConfigFile = filePath;
- IsSharedConfig = true;
- return;
- }
-
- rootDir = Path.Combine(rootDir, "Config");
-
- filePath = Path.Combine(rootDir, AppDomain.CurrentDomain.FriendlyName + "." + configFile);
- if (File.Exists(filePath))
- {
- ConfigFile = filePath;
- return;
- }
- filePath = Path.Combine(rootDir, configFile);
- if (File.Exists(filePath))
- {
- ConfigFile = filePath;
- IsSharedConfig = true;
- return;
- }
- ConfigFile = configFile;
- return;
- }
- }
-
-
-
-
-
- public abstract ILog GetLog(string name);
- }
- }
|