Exemple #1
0
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter)
        {
            if (!IsEnabled(logLevel))
            {
                return;
            }
            var s           = _serviceProvider.GetRequiredService <IServerCallContextProvider>();
            var grpcContext = s.ServerCallContext;

            if (grpcContext != null)
            {
                var logEvent = grpcContext.UserState["logcontext"] as ServerCallContextHttpContextLogEvent;
                if (logEvent == null)
                {
                    return;
                }

                logger.SetProperty("host", grpcContext.Host);
                logger.SetProperty("url", logEvent.Url);
                logger.SetProperty("method", grpcContext.Method);
                logger.SetProperty("requestId", logEvent.RequestId);
                logger.SetProperty("userflag", logEvent.UserFlag);
                logger.SetProperty("platformId", logEvent.PlatformId);
                logger.SetProperty("duration", logEvent.End() + " ms");
            }
            logger.Log(NLog.LogEventInfo.Create(NLog.LogLevel.FromOrdinal((int)logLevel), logName, null, state));
        }
Exemple #2
0
        public static void Logging(ILogObj logObj, LogLevel level = LogLevel.Info)
        {
            lock (LockObj)
            {
                LoggerAll.SetProperty("Tag", $"App.{logObj.Tag()}");

                var log = RootLog.Insert(RootLog.LastIndexOf('}'), $",{logObj.Serialize()}");

                Exception ex = null;
                switch (level)
                {
                case LogLevel.Trace:
                    LoggerAll.Trace(ex, log);
                    break;

                case LogLevel.Debug:
                    LoggerAll.Debug(ex, log);
                    break;

                case LogLevel.Info:
                    LoggerAll.Info(ex, log);
                    break;

                case LogLevel.Warn:
                    LoggerAll.Warn(ex, log);
                    break;

                case LogLevel.Error:
                    LoggerAll.Error(ex, log);
                    break;

                case LogLevel.Fatal:
                    LoggerAll.Fatal(ex, log);
                    break;

                default:
                    break;
                }
            }
        }
Exemple #3
0
        public static void Notify(Message msg, bool callEvent = false, bool WriteToLog = true, bool NotifyByEmail = false)
        {
            try
            {
                StackTrace st     = new StackTrace();
                StackFrame sf     = st.GetFrame(1);
                var        method = sf.GetMethod();

                var status = Status.Info;

//#if NETFRAMEWORK
                switch (msg.Code / 1000)
                {
                case 3:
                    status = Status.Error;
                    break;

                case 2:
                    status = Status.Warning;
                    break;

                case 1:
                    status = Status.Success;
                    break;
                }
                ;
//#endif
                // NOTE: doesn't work with c# 7.3 thats supports by net48 targetframework
                //var status = (msg.Code / 1000) switch
                //{
                //    3 => Status.Error,
                //    2 => Status.Warning,
                //    1 => Status.Success,
                //    _ => Status.Info
                //};


                msg.Sender  = method.DeclaringType.Name;
                msg.Caption = $"{method.Module}-[{status}]-[{msg.Code}]";
                _nLogger.SetProperty("Sender", msg.Sender);
                _nLogger.SetProperty("Code", msg.Code);
                _nLogger.SetProperty("Assistant", GlobalSettings.User);

                if (WriteToLog)
                {
                    _nLogger?.Log(ExceptionLevel_LogLevel[status], string.Concat(msg.Head, "---", msg.DetailedText));
                }

                if (status == Status.Error && NotifyByEmail)
                {
                    SendMessageByEmail(msg);
                }

                if ((int)GlobalSettings.Verbosity <= (int)status || callEvent)
                {
                    NotificationEvent?.Invoke(msg);
                }
            }
            catch (Exception e)
            {
                if (NotificationEvent == null)
                {
                    return;
                }
                e.Data.Add("Assembly", "Regata.Core.Inform.WriteMessage");
                var tstr = e.ToString();
                if (tstr.Length <= 300)
                {
                    _nLogger.Log(NLog.LogLevel.Error, e.ToString());
                }
                else
                {
                    _nLogger.Log(NLog.LogLevel.Error, e.ToString().Substring(0, 300));
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Creates a vMix.State object from its xml representation.
        /// </summary>
        /// <param name="textstate">Xml representation of state object.</param>
        /// <returns></returns>
        public State Create(string textstate)
        {
            if (string.IsNullOrWhiteSpace(textstate))
            {
                return(null);
            }
            if (!textstate.StartsWith("<vmix>"))
            {
                _logger.Error("vMix state was not created, got not xml value.");
                return(null);
            }

            IsInitializing = true;
            //_logger.Info(textstate);
            _logger.SetProperty("APIReturn", textstate);
            //_logger.Info("Creating vMix state form {0}.", textstate);

            try
            {
                XmlSerializer s = new XmlSerializer(typeof(State));
                using (var ms = new MemoryStream())
                {
                    XmlDocument doc = new XmlDocument();
                    if (!textstate.StartsWith("<?xml"))
                    {
                        textstate = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + textstate;
                    }
                    textstate = textstate.
                                Replace(">False<", ">false<").
                                Replace(">True<", ">true<").
                                Replace("\"False\"", "\"false\"").
                                Replace("\"True\"", "\"true\"");
                    doc.LoadXml(textstate);
                    doc.Save(ms);
                    ms.Seek(0, SeekOrigin.Begin);
                    var state = (State)s.Deserialize(ms);
                    state._currentStateText = textstate;

                    state._changedinputs.Clear();
                    foreach (var item in state.Inputs)
                    {
                        state._changedinputs.Add(item.Key);
                    }

                    state.Inputs.Insert(0, new Input()
                    {
                        Key = "0", Title = "[Preview]"
                    });
                    state.Inputs.Insert(0, new Input()
                    {
                        Key = "-1", Title = "[Active]"
                    });



                    IsInitializing = false;
                    if (state != null)
                    {
                        _logger.Debug("vMix state created.");
                    }
                    else
                    {
                        _logger.Error("vMix state not created.");
                    }

                    foreach (var item in state.Inputs)
                    {
                        item.ControlledState = state;
                    }
                    foreach (var item in state.Overlays)
                    {
                        item.ControlledState = state;
                    }

                    OnStateCreated?.Invoke(state, null);
                    state.Configure(_ip, _port);
                    return(state);
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "vMix state was not created.");
                return(null);
            }
        }