public static LogEvent ReadFromJObject(JObject jObject) { if (!jObject.TryGetValue("@t", out _)) { jObject.Add("@t", new JValue(DateTime.UtcNow.ToString("O"))); } if (jObject.TryGetValue("@l", out var levelToken)) { jObject.Remove("@l"); var serilogLevel = LevelMapping.ToSerilogLevel(levelToken.Value <string>()); if (serilogLevel != LogEventLevel.Information) { jObject.Add("@l", new JValue(serilogLevel.ToString())); } jObject.Add(SurrogateLevelProperty.PropertyName, levelToken); } else { jObject.Add(SurrogateLevelProperty.PropertyName, new JValue("Information")); } return(LogEventReader.ReadFromJObject(jObject)); }
public void CanReadWriteLevelMappingXmlFromFile() { LevelMapping readLevelMapping = LevelMappingXmlIo.ReadLevelMapping("TestData", "levelMappingXml.txt"); bool isEqual = this.mapping.Mapping.SequenceEqual(readLevelMapping.Mapping); Assert.IsTrue(isEqual); }
LogEvent ToSerilogEvent(EventEntity evt) { return(new LogEvent( DateTimeOffset.ParseExact(evt.Timestamp, "o", CultureInfo.InvariantCulture).ToLocalTime(), LevelMapping.ToSerilogLevel(evt.Level), string.IsNullOrWhiteSpace(evt.Exception) ? null : new TextException(evt.Exception), new MessageTemplate(evt.MessageTemplateTokens.Select(ToMessageTemplateToken)), evt.Properties.Select(p => CreateProperty(p.Name, p.Value)))); }
public void CanReadWriteLevelMappingXml() { string levelMappingPath = LevelMappingXmlIo.WriteLevelMapping(this.mapping, "Test"); string fileName = Path.GetFileName(levelMappingPath); LevelMapping readLevelMapping = LevelMappingXmlIo.ReadLevelMapping("Test", fileName); bool isEqual = this.mapping.Mapping.SequenceEqual(readLevelMapping.Mapping); Assert.IsTrue(isEqual); }
private void Awake() { this.levelMapping = LevelMappingXmlIo.ReadLevelMapping(); this.animationMappingsDictionary = new Dictionary <BlockAnimationType, GameObject>(); foreach (GameBlockAnimationMapping mapping in this.AnimationMappings) { this.animationMappingsDictionary.Add(mapping.AnimationType, mapping.Animation); } }
protected override async Task <int> Run() { var connection = _connectionFactory.Connect(_connection); // Default will apply the ingest permission var apiKey = await connection.ApiKeys.TemplateAsync(); apiKey.Title = _title; apiKey.InputSettings.AppliedProperties = _properties.Properties .Select(kvp => new InputAppliedPropertyPart { Name = kvp.Key, Value = kvp.Value }) .ToList(); apiKey.InputSettings.UseServerTimestamps = _useServerTimestamps; // If _token is null, a value will be returned when the key is created apiKey.Token = _token; if (_filter != null) { apiKey.InputSettings.Filter = new DescriptiveFilterPart { Filter = (await connection.Expressions.ToStrictAsync(_filter)).StrictExpression, FilterNonStrict = _filter }; } if (_level != null) { apiKey.InputSettings.MinimumLevel = Enum.Parse <LogEventLevel>(LevelMapping.ToFullLevelName(_level)); } apiKey = await connection.ApiKeys.AddAsync(apiKey); if (_token == null && !_output.Json) { Console.WriteLine(apiKey.Token); } else { _output.WriteEntity(apiKey); } return(0); }
public void TestFixtureSetUp() { // Initialize expected values this.gameBoard = new GameBoard(2, 3); this.gameBoard.CreateGameBlock(GameBoard.GameBlockType.ChangeDirection, 0, 0); this.gameBoard.CreateGameBlock(GameBoard.GameBlockType.ExtraMove, 0, 1); this.gameBoard.CreateGameBlock(GameBoard.GameBlockType.MultipleMoves, 0, 2); this.gameBoard.CreateGameBlock(GameBoard.GameBlockType.Normal, 1, 0); this.gameBoard.CreateGameBlock(GameBoard.GameBlockType.Null, 1, 1); this.gameBoard.CreateGameBlock(GameBoard.GameBlockType.Player, 1, 2); this.mapping = new LevelMapping(); this.mapping.GenerateLevelKeys(2); this.mapping.Mapping[1] = "Test1"; this.mapping.Mapping[2] = "Test2"; }
/// <summary> /// Add logging event to configured control /// </summary> /// <param name="loggingEvent">The event to log</param> private void UpdateControl(LoggingEvent loggingEvent) { // There may be performance issues if the buffer gets too long // So periodically clear the buffer if (RichtextBox.TextLength > MaxTextLength) { RichtextBox.Clear(); RichtextBox.AppendText(string.Format("(earlier messages cleared because log length exceeded maximum of {0})\n\n", MaxTextLength)); } // look for a style mapping LevelTextStyle selectedStyle = LevelMapping.Lookup(loggingEvent.Level) as LevelTextStyle; if (selectedStyle != null) { // set the colors of the text about to be appended RichtextBox.SelectionBackColor = selectedStyle.BackColor; RichtextBox.SelectionColor = selectedStyle.TextColor; // alter selection font as much as necessary // missing settings are replaced by the font settings on the control if (selectedStyle.Font != null) { // set Font Family, size and styles RichtextBox.SelectionFont = selectedStyle.Font; } else if (selectedStyle.PointSize > 0 && RichtextBox.Font.SizeInPoints != selectedStyle.PointSize) { // use control's font family, set size and styles float size = selectedStyle.PointSize > 0.0f ? selectedStyle.PointSize : RichtextBox.Font.SizeInPoints; RichtextBox.SelectionFont = new Font(RichtextBox.Font.FontFamily.Name, size, selectedStyle.FontStyle); } else if (RichtextBox.Font.Style != selectedStyle.FontStyle) { // use control's font family and size, set styles RichtextBox.SelectionFont = new Font(RichtextBox.Font, selectedStyle.FontStyle); } } RichtextBox.AppendText(RenderLoggingEvent(loggingEvent)); }
LogEvent ReadSerilogEvent(string clef, out string eventId, out uint eventType) { var jvalue = new JsonTextReader(new StringReader(clef)); if (!(_serializer.Deserialize <JToken>(jvalue) is JObject jobject)) { throw new InvalidDataException($"The line is not a JSON object: `{clef.Trim()}`."); } if (jobject.TryGetValue("@l", out var levelToken)) { jobject.Remove("@l"); jobject.Add("@l", new JValue(LevelMapping.ToSerilogLevel(levelToken.Value <string>()).ToString())); } var raw = LogEventReader.ReadFromJObject(jobject); eventId = "event-0"; if (raw.Properties.TryGetValue("@seqid", out var id) && id is ScalarValue { Value : string sid })
public Color GetColor(float level) { if (!isTidy) { Array.Sort(levelMapping); isTidy = true; } bool hasLowerBound = false; LevelMapping lvLow = new LevelMapping { level = 0, color = Color.black }, lv; for (int i = 0, l = levelMapping.Length; i < l; i++) { lv = levelMapping[i]; if (lv.level < level) { if (i == l - 1) { return(lv.color); } lvLow = lv; hasLowerBound = true; } else if (lv.level > level) { if (!hasLowerBound) { return(lv.color); } return(Color.Lerp(lvLow.color, lv.color, Mathf.InverseLerp(lvLow.level, lv.level, level))); } else { return(lv.color); } } return(Color.black); }
LogEvent ReadSerilogEvent(string clef, out string eventId, out uint eventType) { var jvalue = new JsonTextReader(new StringReader(clef)); if (!(_serializer.Deserialize <JToken>(jvalue) is JObject jobject)) { throw new InvalidDataException($"The line is not a JSON object: `{clef.Trim()}`."); } if (jobject.TryGetValue("@l", out var levelToken)) { jobject.Remove("@l"); jobject.Add("@l", new JValue(LevelMapping.ToSerilogLevel(levelToken.Value <string>()).ToString())); } var raw = LogEventReader.ReadFromJObject(jobject); eventId = "event-0"; if (raw.Properties.TryGetValue("@seqid", out var id) && id is ScalarValue svid && svid.Value is string sid) { eventId = sid; } eventType = 0u; if (raw.Properties.TryGetValue("@i", out var et) && et is ScalarValue svet && svet.Value is string set && uint.TryParse(set, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var uet)) { eventType = uet; } return(raw); }
protected override async Task <int> Run() { var connection = await TryConnectAsync(); if (connection == null) { return(1); } var apiKey = await connection.ApiKeys.TemplateAsync(); apiKey.Title = _title; apiKey.InputSettings.AppliedProperties = _properties.Properties .Select(kvp => new EventPropertyPart(kvp.Key, kvp.Value)) .ToList(); apiKey.InputSettings.UseServerTimestamps = _useServerTimestamps; // If _token is null, a value will be returned when the key is created apiKey.Token = _token; if (_filter != null) { apiKey.InputSettings.Filter = new DescriptiveFilterPart { Filter = (await connection.Expressions.ToStrictAsync(_filter)).StrictExpression, FilterNonStrict = _filter }; } if (_level != null) { apiKey.InputSettings.MinimumLevel = Enum.Parse <LogEventLevel>(LevelMapping.ToFullLevelName(_level)); } apiKey.AssignedPermissions.Clear(); if (_permissions != null) { foreach (var permission in _permissions) { if (!Enum.TryParse <Permission>(permission, out var p)) { Log.Error("Unrecognized permission {Permission}", permission); return(1); } apiKey.AssignedPermissions.Add(p); } } else { apiKey.AssignedPermissions.Add(Permission.Ingest); } apiKey = await connection.ApiKeys.AddAsync(apiKey); if (_token == null && !_output.Json) { Console.WriteLine(apiKey.Token); } else { _output.WriteEntity(apiKey); } return(0); }
public void TestFixtureSetUp() { // Initialize expected values this.gameBoard = new GameBoard(2, 3); this.gameBoard.CreateGameBlock(GameBoard.GameBlockType.ChangeDirection, 0, 0); this.gameBoard.CreateGameBlock(GameBoard.GameBlockType.ExtraMove, 0, 1); this.gameBoard.CreateGameBlock(GameBoard.GameBlockType.MultipleMoves, 0, 2); this.gameBoard.CreateGameBlock(GameBoard.GameBlockType.Normal, 1, 0); this.gameBoard.CreateGameBlock(GameBoard.GameBlockType.Null, 1, 1); this.gameBoard.CreateGameBlock(GameBoard.GameBlockType.Player, 1, 2); this.mapping = new LevelMapping(); this.mapping.GenerateLevelKeys(2); this.mapping.Mapping[1] = "Test1"; this.mapping.Mapping[2] = "Test2"; }
private void Awake() { this.levelMapping = LevelMappingXmlIo.ReadLevelMapping(); }
public void CanConvertAnyTraceEventType([ValueSource(nameof(AllTraceEventTypes))] TraceEventType sourceType) { var mapped = LevelMapping.ToLogEventLevel(sourceType); Assert.That(Enum.GetValues(typeof(LogEventLevel)).Cast <LogEventLevel>().Contains(mapped)); }
public CustomConsoleColorAppender() { this._writeToErrorStream = false; this._levelMapping = new LevelMapping(); }
/// <summary> /// Add a mapping of level to text style - done by the config file /// </summary> /// <param name="mapping">The mapping to add</param> /// <remarks> /// <para> /// Add a <see cref="LevelTextStyle"/> mapping to this appender. /// Each mapping defines the text style for a level. /// </para> /// </remarks> public void AddMapping(LevelTextStyle mapping) { LevelMapping.Add(mapping); }
/// <summary> /// Initialize the options for this appender /// </summary> /// <remarks> /// <para> /// Initialize the level to text style mappings set on this appender. /// </para> /// </remarks> public override void ActivateOptions() { base.ActivateOptions(); LevelMapping.ActivateOptions(); }