/// <summary> /// Adds the elements of an array to the end of this LoggerConfigCollection. /// </summary> /// <param name="items"> /// The array whose elements are to be added to the end of this LoggerConfigCollection. /// </param> public virtual void AddRange(LoggerConfig[] items) { foreach (LoggerConfig item in items) { this.List.Add(item); } }
/// <summary>Combines the configs for the handlers in the distribution set with the group's configuration to generate the activeLoggerConfig, the cached summary of the config that is used to gate allocation and delivery of messages.</summary> public bool UpdateActiveLoggerConfig() { LoggerConfig distHandlerLoggerConfigOr = LoggerConfig.None; //!< the logical "or" of the gates for our distribution handlers at the time they were added. LoggerConfig distHandlerLoggerConfigAnd = LoggerConfig.None; //!< the logical "and" of the gates for our distribution handlers at the time they were added. distHandlerLoggerConfigOr.GroupName = DistGroupName; foreach (DistHandlerInfo dhInfo in distHandlerInfoList) { distHandlerLoggerConfigOr |= dhInfo.LoggerConfig; distHandlerLoggerConfigAnd &= dhInfo.LoggerConfig; } LoggerConfig updatedLoggerConfig = distHandlerLoggerConfigOr & groupLoggerConfigSetting; if (Disabled) updatedLoggerConfig.LogGate = LogGate.None; if (!distHandlerLoggerConfigAnd.SupportsReferenceCountedRelease) updatedLoggerConfig.SupportsReferenceCountedRelease = false; if (activeLoggerConfig.Equals(updatedLoggerConfig)) return false; activeLoggerConfig = updatedLoggerConfig; return true; }
public RoleRepository(HuntContext context) { this.context = context; LoggerConfig.ReadConfiguration(); }
public SqlConnectionCreator(LoggerConfig config) { _config = config; }
public GrpcNlogger(string name, LoggerConfig loggerConfig, IServiceProvider serviceProvider) { _config = loggerConfig; _serviceProvider = serviceProvider; logName = name; }
public LoggerFactory() { _config = new ConfigurationHandler().Read(); }
internal static void AddLogger(this IServiceCollection services, LoggerConfig config = null) { services.AddSingleton <ILogger>(new SerilogLogger(config)); }
/// <summary> /// Adds an instance of type LoggerConfig to the end of this LoggerConfigCollection. /// </summary> /// <param name="value"> /// The LoggerConfig to be added to the end of this LoggerConfigCollection. /// </param> public virtual void Add(LoggerConfig value) { this.List.Add(value); }
/// <summary>Basic constructor.</summary> /// <param name="name">Defines the LMH name.</param> /// <param name="logGate">Defines the LogGate value for messages handled here. Messages with MesgType that is not included in this gate will be ignored.</param> /// <param name="includeFileAndLines">Indicates if this handler should record and save source file and line numbers.</param> /// <param name="supportReferenceCountedRelease">Indicates if this logger supports reference counted log message release.</param> public CommonLogMessageHandlerBase(string name, LogGate logGate, bool includeFileAndLines, bool supportReferenceCountedRelease) { this.name = name; loggerConfig = new LoggerConfig() { GroupName = "LMH:" + name, LogGate = logGate, RecordSourceStackFrame = includeFileAndLines, SupportsReferenceCountedRelease = supportReferenceCountedRelease }; logger = new LogMesgHandlerLogger(this); }
/// <summary> /// Adds an element with the specified key and value to this StringToLoggerConfigMap. /// </summary> /// <param name="key"> /// The String key of the element to add. /// </param> /// <param name="value"> /// The LoggerConfig value of the element to add. /// </param> public virtual void Add(String key, LoggerConfig value) { this.Dictionary.Add(key, value); }
/// <summary> /// Determines whether this StringToLoggerConfigMap contains a specific value. /// </summary> /// <param name="value"> /// The LoggerConfig value to locate in this StringToLoggerConfigMap. /// </param> /// <returns> /// true if this StringToLoggerConfigMap contains an element with the specified value; /// otherwise, false. /// </returns> public virtual bool ContainsValue(LoggerConfig value) { foreach (LoggerConfig item in this.Dictionary.Values) { if (item == value) return true; } return false; }
private static void Configure(LoggerConfig config, IConfiguration configuration) { config = config ?? new LoggerConfig(); var jsonLoggin = configuration.GetSection("JsonLogging").Get <LoggerConfig>(); config.LogLevel = jsonLoggin.LogLevel; config.IgnoreMicrosoftLogs = jsonLoggin.IgnoreMicrosoftLogs; config.IgnoreSystemNetLogs = jsonLoggin.IgnoreSystemNetLogs; config.UseFileLogger = jsonLoggin.UseFileLogger; config.LogFilePath = jsonLoggin.LogFilePath; config.ServiceName = configuration.GetValue <string>(nameof(config.ServiceName)) ?? config.ServiceName; config.ServiceVersion = configuration.GetValue <string>(nameof(config.ServiceVersion)) ?? config.ServiceVersion; var attributes = LoggerConfig.GetDefualtLayout(); // если передавались поля для расширения лога, то добавляем их if (config.LogFields != null) { Mapper.Initialize(cfg => { cfg.CreateMap <JsonField, JsonAttribute>().ConvertUsing <JsonAttributeTypeConverter>(); cfg.CreateMap <JsonLayoutField, JsonLayout>(); }); var jsonAttributes = config.LogFields.Select(x => Mapper.Map <JsonField, JsonAttribute>(x)); attributes.AddRange(jsonAttributes); } // добавляем все поля лога в JsonLayout и записываем в конфиг var jsonLayout = new JsonLayout(); attributes.ForEach(x => jsonLayout.Attributes.Add(x)); var consoleTarget = new ConsoleTarget("all_log") { Layout = jsonLayout }; var fileTarget = new FileTarget("all_log_file") { Layout = jsonLayout, Header = "Log was created at ${longdate}${newline}", Footer = "Log was archived at ${longdate}", FileName = $"{config.LogFilePath}\\current.log", ArchiveFileName = $"{config.LogFilePath}\\archive\\archive_${{shortdate}}.{{##}}.log" }; var nullTarget = new NullTarget("blackHole"); // создаем конфиг NLog var nlogConfig = new LoggingConfiguration(); // добавление переменных для NLog nlogConfig.Variables.Add(nameof(config.ServiceName), config.ServiceName); nlogConfig.Variables.Add(nameof(config.ServiceVersion), config.ServiceVersion); if (config.IgnoreMicrosoftLogs) { nlogConfig.AddRule(NLog.LogLevel.FromOrdinal((int)config.LogLevel), NLog.LogLevel.Off, nullTarget, "Microsoft.*", true); } if (config.IgnoreSystemNetLogs) { nlogConfig.AddRule(NLog.LogLevel.FromOrdinal((int)config.LogLevel), NLog.LogLevel.Off, nullTarget, "System.Net.*", true); } nlogConfig.AddRule(NLog.LogLevel.FromOrdinal((int)config.LogLevel), NLog.LogLevel.Off, consoleTarget); if (config.UseFileLogger) { nlogConfig.AddRule(NLog.LogLevel.FromOrdinal((int)config.LogLevel), NLog.LogLevel.Off, fileTarget); } nlogConfig.AddTarget(nullTarget); nlogConfig.AddTarget(consoleTarget); if (config.UseFileLogger) { nlogConfig.AddTarget(fileTarget); } LogManager.Configuration = nlogConfig; }
/// <summary> /// Добавляем логирование в формате json /// </summary> /// <param name="webHostBuilder"></param> /// <param name="fields">Расширяем поля лога</param> /// <param name="appName">Имя приложения</param> /// <returns></returns> public static IWebHostBuilder AddJsonLogger(this IWebHostBuilder webHostBuilder, LoggerConfig config = null) { return(webHostBuilder .ConfigureLogging(logging => { logging.ClearProviders(); logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); }) .UseNLog() .ConfigureServices((ctx, srv) => { Configure(config, ctx.Configuration); })); }
/// <summary> /// Добавляем логирование в формате json /// </summary> /// <param name="services"></param> /// <param name="fields">Расширяем поля лога</param> /// <param name="appName">Имя приложения</param> public static void AddJsonLogger(this IServiceCollection services, IConfiguration configuration, LoggerConfig config = null) { services.AddLogging(logging => { logging.ClearProviders(); logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); logging.AddNLog(new NLogProviderOptions { CaptureMessageTemplates = true, CaptureMessageProperties = true }); Configure(config, configuration); }); }
/// <summary> /// Return the zero-based index of the first occurrence of a specific value /// in this LoggerConfigCollection /// </summary> /// <param name="value"> /// The LoggerConfig value to locate in the LoggerConfigCollection. /// </param> /// <returns> /// The zero-based index of the first occurrence of the _ELEMENT value if found; /// -1 otherwise. /// </returns> public virtual int IndexOf(LoggerConfig value) { return this.List.IndexOf(value); }
/// <summary> /// Removes the first occurrence of a specific LoggerConfig from this LoggerConfigCollection. /// </summary> /// <param name="value"> /// The LoggerConfig value to remove from this LoggerConfigCollection. /// </param> public virtual void Remove(LoggerConfig value) { this.List.Remove(value); }
public GrpcLoggerProvider(IServiceProvider serviceProvider, LoggerConfig config) { _serviceProvider = serviceProvider; _loggerConfig = config ?? new LoggerConfig(); }
public Logger() { //_config = loggerConfig; _config = new LoggerConfig(); }
/// <summary> /// Configures modules. /// </summary> /// <param name="app"><see cref="IApplicationBuilder"/> instance.</param> /// <param name="env"><see cref="IHostingEnvironment"/> instance.</param> /// <param name="logger"><see cref="ILoggerFactory"/> instance.</param> /// <remarks>This method gets called by the runtime. Use this method to configure the HTTP request pipeline.</remarks> public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger) { LoggerConfig.Register(logger, this.Configuration); EnvironmentConfig.Register(app, env); WebServerConfig.Register(app, this.Configuration); }
public PartialHuntingRepository(HuntContext context) { this.context = context; LoggerConfig.ReadConfiguration(); }
public TextFileReader() { _config = new ConfigurationHandler().Read(); }
internal void BuildLogger() { this.logger = (global::Serilog.Core.Logger)LoggerConfig.CreateLogger() .ForContext("SourceContext", this.nameOfLogger); }
public override void CreateLogger(LoggerConfig config) { if (CreateUI == false) { return; } _loggerConfig = config; _loggerViewModel = new LoggerViewModel(); _loggerViewModel.StreamChanged += (sender, args) => { OnStreamChanged(new StreamChangedEventArgs(args.Name, args.Enabled)); }; _filteredView = CollectionViewSource.GetDefaultView(_loggerViewModel.LogItems); _filteredView.Filter = a => ((LoggerViewModel.LogItem)a).Stream.Enabled; _filteredView.GroupDescriptions.Add(new PropertyGroupDescription("UpdateNumber")); _loggerWindow = new LoggerWindow { Top = config.Top, Left = config.Left, Width = config.Width, Height = config.Height }; _loggerWindow.StreamsListView.DataContext = _loggerViewModel.Streams; _loggerWindow.LogListView.DataContext = _filteredView; _loggerWindow.SaveLogFile += (sender, args) => { SaveLogToFile(); }; _loggerWindow.EnableAllStreams += (sender, args) => { _loggerViewModel.EnableAllStreams(); }; _loggerWindow.DisableAllStreams += (sender, args) => { _loggerViewModel.DisableAllStreams(); }; _loggerWindow.IsVisibleChanged += (sender, args) => _loggerConfig.Visible = _loggerWindow.IsVisible; _loggerWindow.LocationChanged += (sender, args) => _loggerLocationJustChanged = true; _loggerWindow.SizeChanged += (sender, args) => _loggerLocationJustChanged = true; _loggerWindow.SoloRequested += (sender, e) => { foreach (var stream in _loggerViewModel.Streams) { if (stream != e.StreamItem) { stream.Enabled = false; } else { stream.Enabled = true; } } }; if (_loggerConfig.Visible) { _loggerWindow.Show(); } _windows.Add(_loggerWindow); _loggerScrollViewer = GetDescendantByType(_loggerWindow.LogListView, typeof(ScrollViewer)) as ScrollViewer; WindowHelper.EnsureOnScreen(_loggerWindow); }
public override void CreateLogger(LoggerConfig config) { }
public ConsoleLogger() { _config = LoggerConfig.All; }
public UDPLogger(LoggerConfig config) { _host = config.UDP.Host; _port = config.UDP.Port; uc = new System.Net.Sockets.UdpClient(); }
public ConsoleLogger(LoggerConfig config) { _config = config; }
public EditorLogger(LoggerConfig config) { _config = config; }
public NativeLogger(LoggerConfig config) { _config = config; }
/// <summary> /// Determines whether a specfic LoggerConfig value is in this LoggerConfigCollection. /// </summary> /// <param name="value"> /// The LoggerConfig value to locate in this LoggerConfigCollection. /// </param> /// <returns> /// true if value is found in this LoggerConfigCollection; /// false otherwise. /// </returns> public virtual bool Contains(LoggerConfig value) { return this.List.Contains(value); }
public Logger(OwinMiddleware next, ILogger logger) : base(next) { _logger = logger; _options = LoggerConfig.Init(); }
/// <summary> /// Inserts an element into the LoggerConfigCollection at the specified index /// </summary> /// <param name="index"> /// The index at which the LoggerConfig is to be inserted. /// </param> /// <param name="value"> /// The LoggerConfig to insert. /// </param> public virtual void Insert(int index, LoggerConfig value) { this.List.Insert(index, value); }
public NetCoreUtilsLogger(LoggerConfig config = null) { logger = new Logger(config); }
/// <summary> /// Initializes a new instance of the LoggerConfigCollection class, containing elements /// copied from an array. /// </summary> /// <param name="items"> /// The array whose elements are to be added to the new LoggerConfigCollection. /// </param> public LoggerConfigCollection(LoggerConfig[] items) { this.AddRange(items); }
public static void Initialize(LoggerConfig config) { service = new LoggerService(config); displayLevel = config.DisplayLevel; useFullClassName = config.UseFullClassName; }
public FileLogger(LoggerConfig config) { SavePath = config.File.Path; }
protected void Application_End() { LoggerConfig.DisposeLogger(); }
public Logger(Action <string> action) { this.onWrite = action; _config = new LoggerConfig(); }
public Logger(LoggerConfig config) { _config = config; _writer = new LoggerWriter(config.LogFile); }