public void Init(WriterSection config) { string value = config.GetOptionValue("RootPath"); if (string.IsNullOrEmpty(value)) { throw new LogConfigException("日志配置文件中,没有为MsmqWriter指定RootPath属性。"); } if (s_rootPath != null) { return; } // 检查需要记录的各个数据类型的队列是否存在。 foreach (var item in WriterFactory.Config.Types) { string path = value + "-" + item.Type.Name; if (MessageQueue.Exists(path) == false) { using (MessageQueue messageQueue = MessageQueue.Create(path)) { messageQueue.SetPermissions("Everyone", MessageQueueAccessRights.FullControl); } } } s_rootPath = value + "-"; }
/// <summary> /// 获取要显示的日志根目录, /// 重写这个方法可修改默认的根目录(FileWriter指定的目录)。 /// </summary> /// <returns></returns> public virtual string GetLogRootDirectory() { WriterFactory.Init(); WriterSection config = (from x in WriterFactory.Config.Writers where x.Type.StartsWith(typeof(FileWriter).FullName + ",") select x).FirstOrDefault(); if (config == null) { WriteMessage("ClownFish.Log.config中没有配置FileWriter"); return(null); } string path = config.GetOptionValue("RootDirectory"); if (string.IsNullOrEmpty(path)) { WriteMessage("ClownFish.Log.config中,没有为FileWriter指定RootDirectory属性。"); return(null); } path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path); if (Directory.Exists(path) == false) { WriteMessage("ClownFish.Log.config中,为FileWriter指定RootDirectory目录不存在。"); return(null); } return(path); }
/// <summary> /// 初始化 /// </summary> /// <param name="config"></param> public void Init(WriterSection config) { // 避免重复调用 if (s_url != null) { return; } string url = config.GetOptionValue("url"); if (string.IsNullOrEmpty(url)) { throw new LogConfigException("日志配置文件中,没有为HttpWriter指定url属性。"); } string format = config.GetOptionValue("format"); if (string.IsNullOrEmpty(format)) { s_format = SerializeFormat.Xml; // 默认值 } else { if (Enum.TryParse <SerializeFormat>(format, out s_format) == false || s_format == SerializeFormat.None || s_format == SerializeFormat.Auto ) { throw new LogConfigException("日志配置文件中,为HttpWriter指定的format属性无效,建议选择:Json or Xml"); } } s_retryCount = config.GetOptionValue("retry-count").TryToUInt(10); s_retryWaitMillisecond = config.GetOptionValue("retry-wait-millisecond").TryToUInt(1000); s_datatypeInHeader = config.GetOptionValue("datatype-in-header").TryToBool(true); List <NameValue> queryString = ReadHttpArgs(config, "querystring:"); s_header = ReadHttpArgs(config, "header:"); s_url = url.ConcatQueryStringArgs(queryString); s_client = new HttpWriterClient(); }
/// <summary> /// 从配置文件中初始化 /// 注意:仅供框架调用,不需要在代码中调用。 /// </summary> /// <param name="config"></param> public void Init(WriterSection config) { string value = config.GetOptionValue("ConnectionString"); if (string.IsNullOrEmpty(value)) { throw new LogConfigException("日志配置文件中,没有为MongoDbWriter指定ConnectionString属性。"); } s_configSetting = MongoDbSetting.Create(value); }
public virtual void Init(WriterSection config) { string logName = config.GetOptionValue("LogName"); if (string.IsNullOrEmpty(logName)) { throw new LogConfigException("在配置文件中没有为WinLogWriter指定LogName属性。"); } string sourceName = config.GetOptionValue("SourceName"); if (string.IsNullOrEmpty(sourceName)) { throw new LogConfigException("在配置文件中没有为WinLogWriter指定SourceName属性。"); } try { // 尽量尝试为日志消息创建一个目录来存放 // 下面这二个API都需要管理员权限才能调用,在ASP.NET程序中会出现异常 // 当事件源存在时,调用SourceExists()不会出现异常,不存在时才会有异常 if (EventLog.SourceExists(sourceName) == false) { EventLog.CreateEventSource(sourceName, logName); } s_logName = logName; s_sourceName = sourceName; s_initOK = true; } catch (Exception ex) { string xx = ex.Message; // 无用代码,仅用于调试查看错误原因 // 如果权限不够,就直接存在到Application目录中。 // 所以,这里不做异常处理 } // ########### DEBUG INFO //EventLog.WriteEntry("Application Error ", "WinLogWriter.s_initOK: " + s_initOK.ToString()); // ########### DEBUG INFO }
public virtual void Init(WriterSection config) { string value = config.GetOptionValue("RootDirectory"); if (string.IsNullOrEmpty(value)) { throw new LogConfigException("日志配置文件中,没有为FileWriter指定RootDirectory属性。"); } if (s_rootDirectory != null) { return; } s_rootDirectory = DirectoryHelper.InitDirectory(value); string value2 = config.GetOptionValue("MaxLength"); s_maxLength = value2.TryToUInt(100) * 1024L * 1024; }
public virtual void Init(WriterSection config) { string url = config.GetOptionValue("url"); if (string.IsNullOrEmpty(url)) { throw new LogConfigException("日志配置文件中,没有为HttpWriter指定url参数。"); } string format = config.GetOptionValue("format"); _format = (string.IsNullOrEmpty(format) || format.Is("json")) ? SerializeFormat.Json : SerializeFormat.Xml; _retryCount = config.GetOptionValue("retry-count").TryToUInt(10); _retryWaitMillisecond = config.GetOptionValue("retry-wait-millisecond").TryToUInt(1000); _header = ReadHttpArgs(config, "header:"); List <NameValue> queryString = ReadHttpArgs(config, "querystring:"); _url = url.ConcatQueryStringArgs(queryString); }
public void Init(WriterSection config) { string value = config.GetOptionValue("Receivers"); if (string.IsNullOrEmpty(value)) { throw new LogConfigException("日志配置文件中,没有为MailWriter指定Receivers属性。"); } if (s_recipients != null) { return; } s_recipients = value.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries); }
public void Init(WriterSection config) { string value = config.GetOptionValue("RootDirectory"); if (string.IsNullOrEmpty(value)) { throw new LogConfigException("日志配置文件中,没有为FileWriter指定RootDirectory属性。"); } if (s_rootDirectory != null) { return; } // 支持绝对路径,和相对路径 string rootDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, value); // 检查日志根目录是否存在 if (Directory.Exists(rootDirectory) == false) { Directory.CreateDirectory(rootDirectory); } if (rootDirectory.EndsWith("\\") == false) { rootDirectory = rootDirectory + "\\"; } // 检查需要记录的各个数据类型的子目录是否存在。 foreach (var item in WriterFactory.Config.Types) { string path = rootDirectory + item.Type.Name; if (Directory.Exists(path) == false) { Directory.CreateDirectory(path); } } s_rootDirectory = rootDirectory; }
public void Init(WriterSection config) { string value = config.GetOptionValue("RootDirectory"); if (string.IsNullOrEmpty(value)) { throw new LogConfigException("日志配置文件中,没有为JsonWriter指定RootDirectory属性。"); } if (s_rootDirectory != null) { return; } s_rootDirectory = DirectoryHelper.InitDirectory(value); }