public static string getVersion() { if (_versao == null) { _versao = DependencyService.Get <IAppVersion>(); } return(_versao.GetVersion()); }
/// <summary> /// Enrich the log event. /// </summary> /// <param name="logEvent">The log event to enrich.</param> /// <param name="propertyFactory">Factory for creating new properties to add to the event.</param> public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { string version = _appVersion.GetVersion(); if (!String.IsNullOrWhiteSpace(version)) { var versionProperty = propertyFactory.CreateProperty(_propertyName, version); logEvent.AddPropertyIfAbsent(versionProperty); } }
/// <summary> /// Invoke the middleware to include the version of the application. /// </summary> /// <param name="context">The context for the current HTTP request.</param> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="context"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">Thrown when the <paramref name="context"/> doesn't contain a response.</exception> public async Task Invoke(HttpContext context) { Guard.NotNull(context, nameof(context), "Requires a HTTP context to add the application version to the response"); Guard.For(() => context.Response is null, new ArgumentException("Requires a HTTP context with a response to add the application version", nameof(context))); context.Response.OnStarting(() => { string version = _appVersion.GetVersion(); if (String.IsNullOrWhiteSpace(version)) { _logger.LogWarning("Setting current application version halted because the '{Type}' got a blank version", _appVersion.GetType().Name); } else { _logger.LogTrace("Setting current application version response header '{HeaderName}' to '{Version}'", _options.HeaderName, version); context.Response.Headers[_options.HeaderName] = version; } return(Task.CompletedTask); }); await _next(context); }