Exemplo n.º 1
0
        public void Log(string message, string channelName, MessageKind kind = MessageKind.Information, string title = null, params string[] tags)
        {
            // create context
            var context = new SqlLoggerContext(_configuration.Connection);

            // add channel if it doesn't exist
            AddOrUpdateChannel(channelName, context);

            // find channel
            var channel = context.Channels.FirstOrDefault(c => c.Name == channelName);

            // log error for channel not found
            if (channel == null)
            {
                Log($"Channel not found - {channelName}", "historian.errors", MessageKind.Error, "Channel Not Found");
            }

            // create message
            var m = new Entities.Message
            {
                ChannelId = channel.Id,
                Contents  = message,
                Kind      = kind,
                Timestamp = DateTime.Now,
                Title     = title
            };

            // add and save message
            context.Messages.Add(m);
            context.SaveChanges();
        }
Exemplo n.º 2
0
        public void Log(Message message)
        {
            // create context
            var context = new SqlLoggerContext(_configuration.Connection);

            // add channel if it doesn't exist
            AddOrUpdateChannel(message.Channel, context);

            // find channel
            var channel = context.Channels.FirstOrDefault(c => c.Name == message.Channel);

            // log error for channel not found
            if (channel == null)
            {
                Log($"Channel not found - {message.Channel}", "historian.errors", MessageKind.Error, "Channel Not Found");
            }

            // set timestamp, if not set
            if (message.Timestamp == default(DateTime))
            {
                message.Timestamp = DateTime.Now;
            }

            // create message
            var m = new Entities.Message
            {
                ChannelId = channel.Id,
                Contents  = message.Contents,
                Kind      = message.Kind,
                Timestamp = message.Timestamp,
                Title     = message.Title
            };

            // add and save message
            context.Messages.Add(m);
            context.SaveChanges();
        }