/// <summary> /// Initializes a new instance of the <see cref="CloudWatchService"/> class. /// </summary> public CloudWatchService() { PerformanceCounters = new ConcurrentDictionary<PerformanceCounterDescription, PerformanceCounter>(); ManagementServiceHost = new WebServiceHost(new ManagementService(this), new Uri(ManagementService.LocalEndpointUrl)); ManagementServiceHost.AddServiceEndpoint(typeof(IManagementService), new WebHttpBinding(), string.Empty); var config = new NLog.Config.LoggingConfiguration(); config.AddTarget("File", new NLog.Targets.FileTarget() { FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "NCloudWatch", "log.txt") }); config.LoggingRules.Add(new NLog.Config.LoggingRule("*", LogLevel.Info, config.FindTargetByName("File"))); LogManager.Configuration = config; logger = LogManager.GetLogger("NCloudWatch"); }
/// <summary> /// Регистрируем правила Nlog для строки состояния /// </summary> /// <param name="methodName">Имя статического метода который будет вызываться при появлении сообщения.</param> /// <param name="className">Имя класа в котором находится метод.</param> public static void MakeNewStatusTargetForNlog(string methodName, string className) { NLog.Config.LoggingConfiguration config = LogManager.Configuration; if (config.FindTargetByName("status") != null) { return; } NLog.Targets.MethodCallTarget targetLog = new NLog.Targets.MethodCallTarget(); targetLog.Name = "status"; targetLog.MethodName = methodName; targetLog.ClassName = className; targetLog.Parameters.Add(new NLog.Targets.MethodCallParameter("${message}")); config.AddTarget("status", targetLog); NLog.Config.LoggingRule rule = new NLog.Config.LoggingRule("*", targetLog); rule.EnableLoggingForLevel(LogLevel.Info); config.LoggingRules.Add(rule); LogManager.Configuration = config; }