public void WriteAddLogEntryToDatabase() { var target = new DbContextTargetDouble(); target.Write(new LogEventInfo(LogLevel.Debug, LoggerName, "some debug message")); using(var context = new LoggingContext(ConnectionStringName)) { Assert.That(context.Log.Any(e => e.Logger == LoggerName)); } }
public void TearDown() { using(var context = new LoggingContext(ConnectionStringName)) { foreach(var entry in context.Log.Where(e => e.Logger == LoggerName)) { context.Log.Remove(entry); } context.SaveChanges(); } }
// Mappa un oggetto di tipo Category(Infrastructure.logging.datamodel.model) su un oggetto CategoryDAL (Infrastructure.logging.dal) public CategoryDAL categoryToCategoryDAL(Category category) { CategoryDAL categoryDALToBack = new CategoryDAL(); using (var log = new LoggingContext()) { var result = (log.categories.Where(cat => (cat.CategoryId == (int)category.idTipo))); if (result != null) { categoryDALToBack.CategoryId = result.First().CategoryId; categoryDALToBack.name = result.First().name; } } return categoryDALToBack; }
/// <summary> /// Establishes the Call /// </summary> /// <param name="loggingContext">The logging context.</param> /// <returns>Task<TInvitation>.</returns> public abstract Task <TInvitation> EstablishAsync(LoggingContext loggingContext);
/// <inheritdoc cref="ISdkResolverService.ResolveSdk"/> public virtual SdkResult ResolveSdk(int submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, string solutionPath, string projectPath) { // Lazy initialize the SDK resolvers if (_resolvers == null) { Initialize(loggingContext, sdkReferenceLocation); } List <SdkResult> results = new List <SdkResult>(); // Loop through resolvers which have already been sorted by priority, returning the first result that was successful SdkLogger buildEngineLogger = new SdkLogger(loggingContext); loggingContext.LogComment(MessageImportance.Low, "SdkResolving", sdk.ToString()); foreach (SdkResolver sdkResolver in _resolvers) { SdkResolverContext context = new SdkResolverContext(buildEngineLogger, projectPath, solutionPath, ProjectCollection.Version) { State = GetResolverState(submissionId, sdkResolver) }; SdkResultFactory resultFactory = new SdkResultFactory(sdk); SdkResult result; try { result = (SdkResult)sdkResolver.Resolve(sdk, context, resultFactory); } catch (Exception e) when(e is FileNotFoundException || e is FileLoadException && sdkResolver.GetType().GetTypeInfo().Name.Equals("NuGetSdkResolver", StringComparison.Ordinal)) { // Since we explicitly add the NuGetSdkResolver, we special case this. The NuGetSdkResolver has special logic // to load NuGet assemblies at runtime which could fail if the user is not running installed MSBuild. Rather // than give them a generic error, we want to give a more specific message. This exception cannot be caught by // the resolver itself because it is usually thrown before the class is loaded // MSB4243: The NuGet-based SDK resolver failed to run because NuGet assemblies could not be located. Check your installation of MSBuild or set the environment variable "{0}" to the folder that contains the required NuGet assemblies. {1} loggingContext.LogWarning(null, new BuildEventFileInfo(sdkReferenceLocation), "CouldNotRunNuGetSdkResolver", MSBuildConstants.NuGetAssemblyPathEnvironmentVariableName, e.Message); continue; } catch (Exception e) { // MSB4242: The SDK resolver "{0}" failed to run. {1} loggingContext.LogWarning(null, new BuildEventFileInfo(sdkReferenceLocation), "CouldNotRunSdkResolver", sdkResolver.Name, e.Message); continue; } SetResolverState(submissionId, sdkResolver, context.State); if (result == null) { continue; } if (result.Success) { LogWarnings(loggingContext, sdkReferenceLocation, result); if (!IsReferenceSameVersion(sdk, result.Version)) { // MSB4241: The SDK reference "{0}" version "{1}" was resolved to version "{2}" instead. You could be using a different version than expected if you do not update the referenced version to match. loggingContext.LogWarning(null, new BuildEventFileInfo(sdkReferenceLocation), "SdkResultVersionDifferentThanReference", sdk.Name, sdk.Version, result.Version); } // Associate the element location of the resolved SDK reference result.ElementLocation = sdkReferenceLocation; return(result); } results.Add(result); } foreach (SdkResult result in results) { LogWarnings(loggingContext, sdkReferenceLocation, result); if (result.Errors != null) { foreach (string error in result.Errors) { loggingContext.LogErrorFromText(subcategoryResourceName: null, errorCode: null, helpKeyword: null, file: new BuildEventFileInfo(sdkReferenceLocation), message: error); } } } return(new SdkResult(sdk, null, null)); }
private static bool LoadFromCache(string context, HTTPRequest request, Uri uri, LoggingContext loggingContext1 = null, LoggingContext loggingContext2 = null, LoggingContext loggingContext3 = null) { if (HTTPManager.Logger.Level == Logger.Loglevels.All) { HTTPManager.Logger.Verbose("HTTPConnection", string.Format("[{0}] - LoadFromCache for Uri: {1}", context, uri.ToString()), loggingContext1, loggingContext2, loggingContext3); } var cacheEntity = HTTPCacheService.GetEntity(uri); if (cacheEntity == null) { HTTPManager.Logger.Warning("HTTPConnection", string.Format("[{0}] - LoadFromCache for Uri: {1} - Cached entity not found!", context, uri.ToString()), loggingContext1, loggingContext2, loggingContext3); return(false); } request.Response.CacheFileInfo = cacheEntity; try { int bodyLength; using (var cacheStream = cacheEntity.GetBodyStream(out bodyLength)) { if (cacheStream == null) { return(false); } if (!request.Response.HasHeader("content-length")) { request.Response.AddHeader("content-length", bodyLength.ToString()); } request.Response.IsFromCache = true; if (!request.CacheOnly) { request.Response.ReadRaw(cacheStream, bodyLength); } } } catch { return(false); } return(true); }
public static void HandleResponse(string context, HTTPRequest request, out bool resendRequest, out HTTPConnectionStates proposedConnectionState, ref KeepAliveHeader keepAlive, LoggingContext loggingContext1 = null, LoggingContext loggingContext2 = null, LoggingContext loggingContext3 = null) { resendRequest = false; proposedConnectionState = HTTPConnectionStates.Processing; if (request.Response != null) { #if !BESTHTTP_DISABLE_COOKIES // Try to store cookies before we do anything else, as we may remove the response deleting the cookies as well. if (request.IsCookiesEnabled) { CookieJar.Set(request.Response); } #endif switch (request.Response.StatusCode) { // Not authorized // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.2 case 401: { string authHeader = DigestStore.FindBest(request.Response.GetHeaderValues("www-authenticate")); if (!string.IsNullOrEmpty(authHeader)) { var digest = DigestStore.GetOrCreate(request.CurrentUri); digest.ParseChallange(authHeader); if (request.Credentials != null && digest.IsUriProtected(request.CurrentUri) && (!request.HasHeader("Authorization") || digest.Stale)) { resendRequest = true; } } goto default; } // Redirected case 301: // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.2 case 302: // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.3 case 307: // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.8 case 308: // http://tools.ietf.org/html/rfc7238 { if (request.RedirectCount >= request.MaxRedirects) { goto default; } request.RedirectCount++; string location = request.Response.GetFirstHeaderValue("location"); if (!string.IsNullOrEmpty(location)) { Uri redirectUri = ConnectionHelper.GetRedirectUri(request, location); if (HTTPManager.Logger.Level == Logger.Loglevels.All) { HTTPManager.Logger.Verbose("HTTPConnection", string.Format("[{0}] - Redirected to Location: '{1}' redirectUri: '{1}'", context, location, redirectUri), loggingContext1, loggingContext2, loggingContext3); } if (redirectUri == request.CurrentUri) { HTTPManager.Logger.Information("HTTPConnection", string.Format("[{0}] - Redirected to the same location!", context), loggingContext1, loggingContext2, loggingContext3); goto default; } // Let the user to take some control over the redirection if (!request.CallOnBeforeRedirection(redirectUri)) { HTTPManager.Logger.Information("HTTPConnection", string.Format("[{0}] OnBeforeRedirection returned False", context), loggingContext1, loggingContext2, loggingContext3); goto default; } // Remove the previously set Host header. request.RemoveHeader("Host"); // Set the Referer header to the last Uri. request.SetHeader("Referer", request.CurrentUri.ToString()); // Set the new Uri, the CurrentUri will return this while the IsRedirected property is true request.RedirectUri = redirectUri; request.IsRedirected = true; resendRequest = true; } else { throw new Exception(string.Format("[{0}] Got redirect status({1}) without 'location' header!", context, request.Response.StatusCode.ToString())); } goto default; } #if !BESTHTTP_DISABLE_CACHING case 304: if (request.DisableCache) { break; } if (ConnectionHelper.LoadFromCache(context, request, loggingContext1, loggingContext2, loggingContext3)) { request.Timing.Add(TimingEventNames.Loading_From_Cache); HTTPManager.Logger.Verbose("HTTPConnection", string.Format("[{0}] - HandleResponse - Loaded from cache successfully!", context), loggingContext1, loggingContext2, loggingContext3); // Update any caching value HTTPCacheService.SetUpCachingValues(request.CurrentUri, request.Response); } else { HTTPManager.Logger.Verbose("HTTPConnection", string.Format("[{0}] - HandleResponse - Loaded from cache failed!", context), loggingContext1, loggingContext2, loggingContext3); resendRequest = true; } break; #endif default: #if !BESTHTTP_DISABLE_CACHING ConnectionHelper.TryStoreInCache(request); #endif break; } // Closing the stream is done manually? if (request.Response != null && !request.Response.IsClosedManually) { // If we have a response and the server telling us that it closed the connection after the message sent to us, then // we will close the connection too. bool closeByServer = request.Response.HasHeaderWithValue("connection", "close"); bool closeByClient = !request.IsKeepAlive; if (closeByServer || closeByClient) { proposedConnectionState = HTTPConnectionStates.Closed; } else if (request.Response != null) { var keepAliveheaderValues = request.Response.GetHeaderValues("keep-alive"); if (keepAliveheaderValues != null && keepAliveheaderValues.Count > 0) { if (keepAlive == null) { keepAlive = new KeepAliveHeader(); } keepAlive.Parse(keepAliveheaderValues); } } } // Null out the response here instead of the redirected cases (301, 302, 307, 308) // because response might have a Connection: Close header that we would miss to process. // If Connection: Close is present, the server is closing the connection and we would // reuse that closed connection. if (resendRequest) { // Discard the redirect response, we don't need it any more request.Response = null; if (proposedConnectionState == HTTPConnectionStates.Closed) { proposedConnectionState = HTTPConnectionStates.ClosedResendRequest; } } } }
internal override void LogStats(LoggingContext context) { }
/// <summary> /// Creates a new instance. /// </summary> public HistoricPerfDataTable(LoggingContext loggingContext, int initialCapacity = 0) { m_loggingContext = loggingContext; m_table = new ConcurrentBigMap <long, ProcessPipHistoricPerfData>(capacity: initialCapacity); }
/// <summary> /// Creates a <see cref="FingerprintStoreExecutionLogTarget"/>. /// </summary> /// <returns> /// If successful, a <see cref="FingerprintStoreExecutionLogTarget"/> that logs to /// a <see cref="Tracing.FingerprintStore"/> at the provided directory; /// otherwise, null. /// </returns> public static FingerprintStoreExecutionLogTarget Create( PipExecutionContext context, PipTable pipTable, PipContentFingerprinter pipContentFingerprinter, LoggingContext loggingContext, IConfiguration configuration, EngineCache cache, IReadonlyDirectedGraph graph, CounterCollection <FingerprintStoreCounters> counters, IDictionary <PipId, RunnablePipPerformanceInfo> runnablePipPerformance = null, FingerprintStoreTestHooks testHooks = null) { var fingerprintStorePathString = configuration.Layout.FingerprintStoreDirectory.ToString(context.PathTable); var cacheLookupFingerprintStorePathString = configuration.Logging.CacheLookupFingerprintStoreLogDirectory.ToString(context.PathTable); try { FileUtilities.CreateDirectoryWithRetry(fingerprintStorePathString); } catch (BuildXLException ex) { Logger.Log.FingerprintStoreUnableToCreateDirectory(loggingContext, fingerprintStorePathString, ex.Message); throw new BuildXLException("Unable to create fingerprint store directory: ", ex); } var maxEntryAge = new TimeSpan(hours: 0, minutes: configuration.Logging.FingerprintStoreMaxEntryAgeMinutes, seconds: 0); var possibleExecutionStore = FingerprintStore.Open( fingerprintStorePathString, maxEntryAge: maxEntryAge, mode: configuration.Logging.FingerprintStoreMode, loggingContext: loggingContext, counters: counters, testHooks: testHooks); Possible <FingerprintStore> possibleCacheLookupStore = new Failure <string>("No attempt to create a cache lookup fingerprint store yet."); if (configuration.Logging.FingerprintStoreMode != FingerprintStoreMode.ExecutionFingerprintsOnly) { try { FileUtilities.CreateDirectoryWithRetry(cacheLookupFingerprintStorePathString); } catch (BuildXLException ex) { Logger.Log.FingerprintStoreUnableToCreateDirectory(loggingContext, fingerprintStorePathString, ex.Message); throw new BuildXLException("Unable to create fingerprint store directory: ", ex); } possibleCacheLookupStore = FingerprintStore.Open( cacheLookupFingerprintStorePathString, maxEntryAge: maxEntryAge, mode: configuration.Logging.FingerprintStoreMode, loggingContext: loggingContext, counters: counters, testHooks: testHooks); } if (possibleExecutionStore.Succeeded && (possibleCacheLookupStore.Succeeded || configuration.Logging.FingerprintStoreMode == FingerprintStoreMode.ExecutionFingerprintsOnly)) { return(new FingerprintStoreExecutionLogTarget( loggingContext, context, pipTable, pipContentFingerprinter, possibleExecutionStore.Result, possibleCacheLookupStore.Succeeded ? possibleCacheLookupStore.Result : null, configuration, cache, graph, counters, runnablePipPerformance)); } else { if (!possibleExecutionStore.Succeeded) { Logger.Log.FingerprintStoreUnableToOpen(loggingContext, possibleExecutionStore.Failure.DescribeIncludingInnerFailures()); } if (!possibleCacheLookupStore.Succeeded) { Logger.Log.FingerprintStoreUnableToOpen(loggingContext, possibleCacheLookupStore.Failure.DescribeIncludingInnerFailures()); } } return(null); }
/// <summary> /// Logs statistics about the cache /// </summary> internal abstract void LogStats(LoggingContext context);
/// <nodoc/> public FileAccessReporter() { PathTable = new PathTable(); m_loggingContext = new LoggingContext(nameof(FileAccessReporter)); }
/// <summary> /// Creates a new <see cref="FrontEndContext"/> and copies <see cref="PathTable"/>, /// <see cref="SymbolTable"/>, and <see cref="CancellationToken"/> over to it. /// </summary> public FrontEndContext ToFrontEndContext(LoggingContext loggingContext) { return(new FrontEndContext(this, loggingContext, FileSystem)); }
internal FrontEndEngineImplementation( LoggingContext loggingContext, PathTable pathTable, IConfiguration configuration, IStartupConfiguration startupConfiguration, MountsTable mountsTable, InputTracker inputTracker, SnapshotCollector snapshotCollector, DirectoryTranslator directoryTranslator, Func <FileContentTable> getFileContentTable, int timerUpdatePeriod, bool isPartialReuse) { Contract.Requires(loggingContext != null); Contract.Requires(pathTable != null); Contract.Requires(configuration != null); Contract.Requires(startupConfiguration != null); Contract.Requires(mountsTable != null); Contract.Requires(inputTracker != null); Contract.Requires(getFileContentTable != null); m_loggingContext = loggingContext; PathTable = pathTable; m_mountsTable = mountsTable; m_inputTracker = inputTracker; m_getFileContentTable = getFileContentTable; m_isPartialReuse = isPartialReuse; m_snapshotCollector = snapshotCollector; GetTimerUpdatePeriod = timerUpdatePeriod; Layout = configuration.Layout; if (ShouldUseSpecCache(configuration)) { m_specCache = new FileCombiner( loggingContext, Path.Combine(configuration.Layout.EngineCacheDirectory.ToString(PathTable), SpecCacheFileName), FileCombiner.FileCombinerUsage.SpecFileCache, configuration.FrontEnd.LogStatistics); } m_allBuildParameters = new ConcurrentDictionary <string, TrackedValue>(StringComparer.OrdinalIgnoreCase); foreach (var kvp in PopulateFromEnvironmentAndApplyOverrides(startupConfiguration.Properties).ToDictionary()) { m_allBuildParameters.TryAdd(kvp.Key, new TrackedValue(kvp.Value, false)); } m_localDiskContentStore = new LocalDiskContentStore( loggingContext, PathTable, m_getFileContentTable(), m_inputTracker.FileChangeTracker, directoryTranslator, vfsCasRoot: configuration.Cache.VfsCasRoot); m_localDiskContentStoreConcurrencyLimiter = new ActionBlockSlim <MaterializeFileRequest>( Environment.ProcessorCount, request => { var requestCompletionSource = request.CompletionSource; try { var materializeResult = m_localDiskContentStore.TryMaterializeAsync( request.Cache, request.FileRealizationModes, request.Path, request.ContentHash, trackPath: request.TrackPath, recordPathInFileContentTable: request.RecordPathInFileContentTable).GetAwaiter().GetResult(); requestCompletionSource.SetResult(materializeResult); } catch (TaskCanceledException) { requestCompletionSource.SetCanceled(); } catch (Exception e) { requestCompletionSource.SetException(e); } }); }
internal static string GetFrameID(ILoggingContext context) { LoggingContext ctx = (LoggingContext)context; return(ctx.UID.ToString("N")); }
/// <summary> /// Class constructor /// </summary> public GrpcOrchestratorServer(LoggingContext loggingContext, OrchestratorService orchestratorService, string buildId) { m_loggingContext = loggingContext; m_orchestratorService = orchestratorService; m_buildId = buildId; }
/// <summary> /// Retrieve the running time table from the cache /// </summary> public static async Task <Possible <bool> > TryRetrieveRunningTimeTableAsync( this EngineCache cache, LoggingContext loggingContext, string path, PathTable pathTable, ContentFingerprint graphSemistableFingerprint, CancellationToken cancellationToken, DateTime?time = null) { var possibleCacheEntry = await cache.TwoPhaseFingerprintStore.TryGetLatestCacheEntryAsync(loggingContext, graphSemistableFingerprint, time); if (!possibleCacheEntry.Succeeded) { Logger.Log.HistoricPerfDataCacheTrace( loggingContext, I($"Failed loading running time table entry from cache: Failure:{possibleCacheEntry.Failure.DescribeIncludingInnerFailures()}")); return(possibleCacheEntry.Failure); } Logger.Log.HistoricPerfDataCacheTrace( loggingContext, I($"Loaded running time table entry from cache: Fingerprint='{graphSemistableFingerprint}' MetadataHash={possibleCacheEntry.Result?.MetadataHash ?? ContentHashingUtilities.ZeroHash}")); if (!possibleCacheEntry.Result.HasValue) { return(false); } var runningTimeTableHash = possibleCacheEntry.Result.Value.MetadataHash; var absolutePath = AbsolutePath.Create(pathTable, path); var maybePinned = await cache.ArtifactContentCache.TryLoadAvailableContentAsync(new[] { runningTimeTableHash }, cancellationToken); var result = await maybePinned.ThenAsync( async pinResult => { if (!pinResult.AllContentAvailable) { return(new Failure <string>(I($"Could not pin content for running time table '{runningTimeTableHash}'"))); } return(await cache.ArtifactContentCache.TryMaterializeAsync( FileRealizationMode.Copy, absolutePath.Expand(pathTable), runningTimeTableHash, cancellationToken)); }); if (!result.Succeeded) { Logger.Log.HistoricPerfDataCacheTrace( loggingContext, I($"Failed loading running time table from cache: Failure:{result.Failure.DescribeIncludingInnerFailures()}")); return(result.Failure); } Logger.Log.HistoricPerfDataCacheTrace(loggingContext, I($"Loaded running time table from cache: Path='{path}'")); return(true); }
/// <summary> /// Terminates the Call /// </summary> /// <param name="loggingContext">The logging context.</param> /// <returns>Task.</returns> public abstract Task TerminateAsync(LoggingContext loggingContext);
public async Task TestHistoricMetadataPathStringRoundtrip() { LoggingContext loggingContext = CreateLoggingContextForTest(); PipExecutionContext context; HistoricMetadataCache cache = null; var hmcFolderName = "hmc"; for (int i = 0; i < 3; i++) { CreateHistoricCache(loggingContext, hmcFolderName, out context, out cache, out var memoryArtifactCache); var process1 = CreateDummyProcess(context, new PipId(1)); var process2 = CreateDummyProcess(context, new PipId(2)); var pathTable = context.PathTable; // Add some random paths to ensure path table indices are different after loading AbsolutePath.Create(pathTable, X("/H/aslj/sfas/832.stxt")); AbsolutePath.Create(pathTable, X("/R/f/s/Historic")); AbsolutePath.Create(pathTable, X("/M/hgf/sf4as/83afsd")); AbsolutePath.Create(pathTable, X("/Z/bd/sfas/Cache")); var abPath1 = AbsolutePath.Create(pathTable, X("/H/aslj/sfas/p1OUT.bin")); var abPath2 = AbsolutePath.Create(pathTable, X("/H/aslj/sfas/P2.txt")); var pathSet1 = ObservedPathSetTestUtilities.CreatePathSet( pathTable, X("/X/a/b/c"), X("/X/d/e"), X("/X/a/b/c/d")); PipCacheDescriptorV2Metadata metadata1 = new PipCacheDescriptorV2Metadata { StaticOutputHashes = new List <AbsolutePathFileMaterializationInfo> { new AbsolutePathFileMaterializationInfo { AbsolutePath = abPath1.GetName(pathTable).ToString(context.StringTable), Info = new BondFileMaterializationInfo { FileName = "p1OUT.bin" } } } }; var storedPathSet1 = await cache.TryStorePathSetAsync(pathSet1); var storedMetadata1 = await cache.TryStoreMetadataAsync(metadata1); var weakFingerprint1 = new WeakContentFingerprint(FingerprintUtilities.CreateRandom()); var strongFingerprint1 = new StrongContentFingerprint(FingerprintUtilities.CreateRandom()); var cacheEntry = new CacheEntry(storedMetadata1.Result, nameof(HistoricMetadataCacheTests), ArrayView <ContentHash> .Empty); var publishedCacheEntry = await cache.TryPublishCacheEntryAsync(process1, weakFingerprint1, storedPathSet1.Result, strongFingerprint1, cacheEntry); var pathSet2 = ObservedPathSetTestUtilities.CreatePathSet( pathTable, X("/F/a/y/c"), X("/B/d/e"), X("/G/a/z/c/d"), X("/B/a/b/c")); PipCacheDescriptorV2Metadata metadata2 = new PipCacheDescriptorV2Metadata { StaticOutputHashes = new List <AbsolutePathFileMaterializationInfo> { new AbsolutePathFileMaterializationInfo { AbsolutePath = abPath2.ToString(pathTable), Info = new BondFileMaterializationInfo { FileName = abPath2.GetName(pathTable).ToString(context.StringTable) } } }, DynamicOutputs = new List <List <RelativePathFileMaterializationInfo> > { new List <RelativePathFileMaterializationInfo> { new RelativePathFileMaterializationInfo { RelativePath = @"dir\P2Dynamic.txt", Info = new BondFileMaterializationInfo { FileName = "p2dynamic.txt" } }, new RelativePathFileMaterializationInfo { RelativePath = @"dir\P2dynout2.txt", Info = new BondFileMaterializationInfo { FileName = null } } } } }; var storedPathSet2 = await cache.TryStorePathSetAsync(pathSet2); var storedMetadata2 = await cache.TryStoreMetadataAsync(metadata2); var cacheEntry2 = new CacheEntry(storedMetadata2.Result, nameof(HistoricMetadataCacheTests), ArrayView <ContentHash> .Empty); var strongFingerprint2 = new StrongContentFingerprint(FingerprintUtilities.CreateRandom()); var publishedCacheEntry2 = await cache.TryPublishCacheEntryAsync(process1, weakFingerprint1, storedPathSet2.Result, strongFingerprint2, cacheEntry2); await cache.CloseAsync(); memoryArtifactCache.Clear(); PipExecutionContext loadedContext; HistoricMetadataCache loadedCache; TaskSourceSlim <bool> loadCompletionSource = TaskSourceSlim.Create <bool>(); TaskSourceSlim <bool> loadCalled = TaskSourceSlim.Create <bool>(); BoxRef <bool> calledLoad = new BoxRef <bool>(); CreateHistoricCache(loggingContext, "hmc", out loadedContext, out loadedCache, out memoryArtifactCache, loadTask: async hmc => { loadCalled.SetResult(true); await loadCompletionSource.Task; }); var operationContext = OperationContext.CreateUntracked(loggingContext); var retrievePathSet1Task = loadedCache.TryRetrievePathSetAsync(operationContext, WeakContentFingerprint.Zero, storedPathSet1.Result); var retrievdMetadata1Task = loadedCache.TryRetrieveMetadataAsync( process1, WeakContentFingerprint.Zero, StrongContentFingerprint.Zero, storedMetadata1.Result, storedPathSet1.Result); var getCacheEntry1Task = loadedCache.TryGetCacheEntryAsync( process1, weakFingerprint1, storedPathSet1.Result, strongFingerprint1); Assert.False(retrievePathSet1Task.IsCompleted, "Before load task completes. TryRetrievePathSetAsync operations should block"); Assert.False(retrievdMetadata1Task.IsCompleted, "Before load task completes. TryRetrieveMetadataAsync operations should block"); Assert.False(getCacheEntry1Task.IsCompleted, "Before load task completes. TryGetCacheEntryAsync operations should block"); Assert.True(loadCalled.Task.Wait(TimeSpan.FromSeconds(10)) && loadCalled.Task.Result, "Load should have been called in as a result of querying"); loadCompletionSource.SetResult(true); var maybeLoadedPathSet1 = await retrievePathSet1Task; var maybeLoadedMetadata1 = await retrievdMetadata1Task; var maybeLoadedCacheEntry1 = await getCacheEntry1Task; Assert.Equal(storedMetadata1.Result, maybeLoadedCacheEntry1.Result.Value.MetadataHash); var maybeLoadedPathSet2 = await loadedCache.TryRetrievePathSetAsync(operationContext, WeakContentFingerprint.Zero, storedPathSet2.Result); var maybeLoadedMetadata2 = await loadedCache.TryRetrieveMetadataAsync( process2, WeakContentFingerprint.Zero, StrongContentFingerprint.Zero, storedMetadata2.Result, storedPathSet2.Result); AssertPathSetEquals(pathTable, pathSet1, loadedContext.PathTable, maybeLoadedPathSet1.Result); AssertPathSetEquals(pathTable, pathSet2, loadedContext.PathTable, maybeLoadedPathSet2.Result); AssertMetadataEquals(metadata1, maybeLoadedMetadata1.Result); AssertMetadataEquals(metadata2, maybeLoadedMetadata2.Result); await loadedCache.CloseAsync(); } }
public EventsChannelContext(EventsEntity eventsEntity, LoggingContext loggingContext = null) { this.EventsEntity = eventsEntity; this.LoggingContext = loggingContext; }
public override async Task <IMessagingInvitation> EstablishAsync(LoggingContext loggingContext) { string href = PlatformResource?.AddMessagingLink?.Href; if (string.IsNullOrWhiteSpace(href)) { throw new CapabilityNotAvailableException("Link to establish messaging is not available."); } Logger.Instance.Information(string.Format("[Messaging] calling AddMessaging. LoggingContext: {0}", loggingContext == null ? string.Empty : loggingContext.ToString())); var conversation = base.Parent as Conversation; if (conversation == null) { Logger.Instance.Error("[Messaging] Conversation from messaging base parent is numll"); throw new Exception("[Messaging] Failed to get Conversation from messaging base parent"); } var communication = conversation.Parent as Communication; if (communication == null) { Logger.Instance.Error("[Messaging] communication from conversation base parent is numll"); throw new Exception("[Messaging] Failed to get communication from conversation base parent"); } string operationId = Guid.NewGuid().ToString(); TaskCompletionSource <IInvitation> tcs = new TaskCompletionSource <IInvitation>(); //Tracking the incoming invitation from communication resource communication.HandleNewInviteOperationKickedOff(operationId, tcs); IInvitation invite = null; //It seems that this is not the expected input, please clarify the right input resource here. var input = new MessagingInvitationInput { OperationContext = operationId, }; Uri addMessagingUri = UriHelper.CreateAbsoluteUri(this.BaseUri, href); await this.PostRelatedPlatformResourceAsync(addMessagingUri, input, new ResourceJsonMediaTypeFormatter(), loggingContext).ConfigureAwait(false); try { invite = await tcs.Task.TimeoutAfterAsync(WaitForEvents).ConfigureAwait(false); } catch (TimeoutException) { throw new RemotePlatformServiceException("Timeout to get incoming messaging invitation started event from platformservice!"); } //We are sure the invite sure be there now. var result = invite as IMessagingInvitation; if (result == null) { throw new RemotePlatformServiceException("Platformservice do not deliver a messageInvitation resource with operationId " + operationId); } return(result); }
public void OneTimeTearDown() { LoggingContext.ResetToDefault(); }
internal static async Task <Possible <CacheCoreCacheInitializer> > TryInitializeCacheInternalAsync( LoggingContext loggingContext, PathTable pathTable, string cacheDirectory, ICacheConfiguration config, bool enableFingerprintLookup, RootTranslator rootTranslator) { Contract.Requires(pathTable != null); Contract.Requires(pathTable.IsValid); Contract.Requires(config != null); Contract.Requires(config.CacheLogFilePath.IsValid); Contract.Requires(config.CacheConfigFile.IsValid); Contract.Requires(!string.IsNullOrWhiteSpace(cacheDirectory)); bool succeeded = false; ICacheCoreCache cache = null; ICacheCoreSession session = null; try { Possible <ICacheConfigData> cacheConfigData = TryGetCacheConfigData(pathTable, cacheDirectory, config); if (!cacheConfigData.Succeeded) { return(cacheConfigData.Failure); } Possible <ICacheCoreCache> maybeCache = await CacheFactory.InitializeCacheAsync(cacheConfigData.Result, loggingContext.ActivityId); if (!maybeCache.Succeeded) { return(maybeCache.Failure); } // We are now responsible for shutting this down (even if something later fails). cache = maybeCache.Result; cache.SuscribeForCacheStateDegredationFailures( failure => { Tracing.Logger.Log.CacheReportedRecoverableError(loggingContext, failure.DescribeIncludingInnerFailures()); }); // Log the cache ID we got. Tracing.Logger.Log.CacheInitialized(loggingContext, cache.CacheId); Possible <ICacheCoreSession> maybeSession = string.IsNullOrWhiteSpace(config.CacheSessionName) ? await cache.CreateSessionAsync() : await cache.CreateSessionAsync(config.CacheSessionName); if (!maybeSession.Succeeded) { return(maybeSession.Failure); } session = maybeSession.Result; succeeded = true; return(new CacheCoreCacheInitializer( loggingContext, cache, session, new List <IDisposable>(), enableFingerprintLookup: enableFingerprintLookup, rootTranslator: rootTranslator)); } finally { if (!succeeded) { // Note that we clean up in reverse order that we initialized things. if (session != null) { Analysis.IgnoreResult(await session.CloseAsync(), justification: "Okay to ignore close"); Analysis.IgnoreResult(await cache.ShutdownAsync(), justification: "Okay to ignore shutdown"); } } } }
public void TestSetup() { LoggingContext.ResetToDefault(); }
public static CacheInitializationTask GetCacheInitializationTask( LoggingContext loggingContext, PathTable pathTable, string cacheDirectory, ICacheConfiguration config, RootTranslator rootTranslator, bool?recoveryStatus, CancellationToken cancellationToken, // Only used for testing purposes to inject cache. Func <EngineCache> testHookCacheFactory = null) { Contract.Requires(recoveryStatus.HasValue, "Recovery attempt should have been done before initializing the cache"); DateTime startTime = DateTime.UtcNow; var task = Task.Run( async() => { using (PerformanceMeasurement.Start( loggingContext, "CacheInitialization", Tracing.Logger.Log.StartInitializingCache, Tracing.Logger.Log.EndInitializingCache)) { if (testHookCacheFactory != null) { return(new MemoryCacheInitializer( testHookCacheFactory, loggingContext, new List <IDisposable>(), enableFingerprintLookup: config.Incremental)); } Possible <CacheCoreCacheInitializer> maybeCacheCoreEngineCache = await CacheCoreCacheInitializer.TryInitializeCacheInternalAsync( loggingContext, pathTable, cacheDirectory, config, enableFingerprintLookup: config.Incremental, rootTranslator: rootTranslator); if (!maybeCacheCoreEngineCache.Succeeded) { string errorMessage = maybeCacheCoreEngineCache.Failure.Describe(); if (errorMessage.Contains(LockAcquisitionFailureMessagePrefix)) { Tracing.Logger.Log.FailedToAcquireDirectoryLock( loggingContext, maybeCacheCoreEngineCache.Failure.DescribeIncludingInnerFailures()); } else { Tracing.Logger.Log.StorageCacheStartupError( loggingContext, maybeCacheCoreEngineCache.Failure.DescribeIncludingInnerFailures()); } } return(maybeCacheCoreEngineCache.Then <CacheInitializer>(c => c)); } }, cancellationToken); return(new CacheInitializationTask( loggingContext, startTime, task, cancellationToken)); }
private static Optional <CompositeGraphFingerprint> GenerateHash( LoggingContext loggingContext, IStartupConfiguration startUpConfig, IConfiguration config, PathTable pathTable, IEvaluationFilter partialEvaluationData, FileContentTable fileContentTable, string commitId, EngineTestHooksData testHooks) { ILayoutConfiguration layout = config.Layout; ILoggingConfiguration logging = config.Logging; var fingerprintTextElements = new List <(string, string)>(); using (var hasher = new CoreHashingHelper(recordFingerprintString: true)) { CompositeGraphFingerprint fingerprint = CompositeGraphFingerprint.Zero; using (var qualifierHasher = new CoreHashingHelper(recordFingerprintString: false)) { foreach (string qualifier in startUpConfig.QualifierIdentifiers.OrderBy(q => q)) { AddText(qualifierHasher, "qualifier", qualifier); } fingerprint.QualifierHash = qualifierHasher.GenerateHash(); AddFingerprint(hasher, "Qualifiers", fingerprint.QualifierHash); } if (partialEvaluationData != null && partialEvaluationData.CanPerformPartialEvaluation) { using (var evaluationFilterHasher = new CoreHashingHelper(recordFingerprintString: false)) { AddOrderedTextValues(evaluationFilterHasher, "valueName", partialEvaluationData.ValueNamesToResolveAsStrings); AddOrderedTextValues(evaluationFilterHasher, "valuePath", partialEvaluationData.ValueDefinitionRootsToResolveAsStrings); AddOrderedTextValues(evaluationFilterHasher, "moduleName", partialEvaluationData.ModulesToResolveAsStrings); fingerprint.FilterHash = evaluationFilterHasher.GenerateHash(); AddFingerprint(hasher, "Values", fingerprint.FilterHash); } } using (var topLevelHasher = new CoreHashingHelper(recordFingerprintString: false)) { AddInt(topLevelHasher, "version", GraphFingerprintVersion); // These paths get embedded in the result of evaluation. So if any change we must re-evaluate AddText(topLevelHasher, "ObjectDirectoryPath", layout.ObjectDirectory.IsValid ? layout.ObjectDirectory.ToString(pathTable) : "::null::"); AddText(topLevelHasher, "TempDirectoryPath", layout.TempDirectory.IsValid ? layout.TempDirectory.ToString(pathTable) : "::null::"); AddText(topLevelHasher, "SourceDirectoryPath", layout.SourceDirectory.IsValid ? layout.SourceDirectory.ToString(pathTable) : "::null::"); // All paths in the graph are relative to 'substTarget' (hence, 'substTarget' must be a part of the fingerprint, but 'substSource' need not be). AddText(topLevelHasher, "substTarget", logging.SubstTarget.IsValid ? logging.SubstTarget.ToString(pathTable) : "::null::"); AddText(topLevelHasher, "IsCompressed", config.Engine.CompressGraphFiles ? "true" : "false"); AddText(topLevelHasher, "IsSkipHashSourceFile", config.Schedule.SkipHashSourceFile ? "true" : "false"); // Pip static fingerprints are not always computed because computing them slows down the graph construction by 10%-13%. // Thus, the pip graph may and may not contain pip static fingerprints. To avoid unexpected result due to graph cache hit, // we temporarily add the option for computing pip static fingerprints as part of our graph fingerprint until the fingerprints // are always computed; see Task 1291638. AddText(topLevelHasher, "ComputePipStaticFingerprints", config.Schedule.ComputePipStaticFingerprints.ToString()); AddText(topLevelHasher, "HostOS", startUpConfig.CurrentHost.CurrentOS.ToString()); AddText(topLevelHasher, "HostCpuArchitecture", startUpConfig.CurrentHost.CpuArchitecture.ToString()); AddText(topLevelHasher, "HostIsElevated", CurrentProcess.IsElevated.ToString()); var salt = string.Empty; if (testHooks?.GraphFingerprintSalt != null) { salt += testHooks.GraphFingerprintSalt.Value.ToString(); } salt += EngineEnvironmentSettings.DebugGraphFingerprintSalt; if (!string.IsNullOrEmpty(salt)) { AddText(topLevelHasher, "GraphFingerprintSalt", salt); } if (config.Schedule.ComputePipStaticFingerprints) { // Pip static fingerprints are part of the graph and include the extra fingerprint salts. // Thus, when pip static fingerprints are computed, any change to the salt will invalidate the graph because // the pip static fingerprints will no longer be valid. Reusing the graph when the salt changes can result in // underbuild. var extraFingerprintSalts = new ExtraFingerprintSalts( config, PipFingerprintingVersion.TwoPhaseV2, config.Cache.CacheSalt ?? string.Empty, new Scheduler.DirectoryMembershipFingerprinterRuleSet(config, pathTable.StringTable).ComputeSearchPathToolsHash()); AddFingerprint(topLevelHasher, "ExtraFingerprintSalts", extraFingerprintSalts.CalculatedSaltsFingerprint); } fingerprint.TopLevelHash = topLevelHasher.GenerateHash(); AddFingerprint(hasher, "TopLevelHash", fingerprint.TopLevelHash); } // Config files // Caution: Including the content hash of the config file is how changes to the default pip filter // invalidate a cached graph. If the config file content hash is removed, the values that get // evaluated because of it must be reflected in the values passed in to this method. using (var configHasher = new CoreHashingHelper(recordFingerprintString: false)) { var configFiles = new List <AbsolutePath> { startUpConfig.ConfigFile }; if (startUpConfig.AdditionalConfigFiles != null) { configFiles.AddRange(startUpConfig.AdditionalConfigFiles); } try { foreach (var configPath in configFiles .Select(path => path.ToString(pathTable)) .OrderBy(c => c, OperatingSystemHelper.PathComparer)) { AddContentHash( configHasher, configPath.ToCanonicalizedPath(), fileContentTable.GetAndRecordContentHashAsync(configPath) .GetAwaiter() .GetResult() .VersionedFileIdentityAndContentInfo.FileContentInfo.Hash); } fingerprint.ConfigFileHash = configHasher.GenerateHash(); AddFingerprint(hasher, "ConfigFiles", fingerprint.ConfigFileHash); } catch (BuildXLException ex) { return(LogAndReturnFailure(loggingContext, ex)); } } if (!string.IsNullOrEmpty(commitId)) { using (var commitHasher = new CoreHashingHelper(recordFingerprintString: false)) { commitHasher.Add("Commit", commitId); fingerprint.BuildEngineHash = commitHasher.GenerateHash(); } AddFingerprint(hasher, "BuildEngine", fingerprint.BuildEngineHash); } else { // BuildXL assemblies. This will invalidate the cached graph if build files change // or if the serialization format changes. try { Action <string, ContentHash> handleBuildFileAndHash = (buildFile, buildFileHash) => { // Directly add to fingerprint elements for logging, but the hash is represented in the build engine hash fingerprintTextElements.Add((buildFile, buildFileHash.ToString())); }; var deployment = testHooks?.AppDeployment ?? AppDeployment.ReadDeploymentManifestFromRunningApp(); fingerprint.BuildEngineHash = deployment.ComputeContentHashBasedFingerprint(fileContentTable, handleBuildFileAndHash); AddFingerprint(hasher, "BuildEngine", fingerprint.BuildEngineHash); } catch (BuildXLException ex) { Tracing.Logger.Log.FailedToComputeHashFromDeploymentManifest(loggingContext); Tracing.Logger.Log.FailedToComputeHashFromDeploymentManifestReason(loggingContext, ex.Message); return(default(Optional <CompositeGraphFingerprint>)); } } fingerprint.OverallFingerprint = new ContentFingerprint(hasher.GenerateHash()); Tracing.Logger.Log.ElementsOfConfigurationFingerprint( loggingContext, fingerprint.OverallFingerprint.ToString(), string.Join(Environment.NewLine, fingerprintTextElements.Select(kvp => "\t" + kvp.Item1 + " : " + kvp.Item2))); return(new Optional <CompositeGraphFingerprint>(fingerprint)); } // Local functions void AddInt(CoreHashingHelper hasher, string key, int value) { hasher.Add(key, value); fingerprintTextElements.Add( (key, value.ToString(CultureInfo.InvariantCulture))); } void AddOrderedTextValues(CoreHashingHelper hasher, string key, IReadOnlyList <string> values) { // Limit the number of printed values to 50 to make logging more manageable. NOTE: // values still go into fingerprint even if they are not printed. const int maxValuesToPrint = 50; var unprintedValueCount = values.Count - maxValuesToPrint; int i = 0; foreach (var value in values.OrderBy(s => s)) { hasher.Add(key, value); if (i < maxValuesToPrint) { fingerprintTextElements.Add((key, value)); } else if (i == maxValuesToPrint) { fingerprintTextElements.Add((key, $"[+{unprintedValueCount} more]")); } i++; } } void AddText(CoreHashingHelper hasher, string key, string value) { hasher.Add(key, value); fingerprintTextElements.Add((key, value)); } void AddFingerprint(CoreHashingHelper hasher, string key, Fingerprint value) { hasher.Add(key, value); fingerprintTextElements.Add((key, value.ToString())); } void AddContentHash(CoreHashingHelper hasher, string key, ContentHash value) { hasher.Add(key, value); fingerprintTextElements.Add((key, value.ToString())); } }
public static bool LoadFromCache(string context, HTTPRequest request, LoggingContext loggingContext1 = null, LoggingContext loggingContext2 = null, LoggingContext loggingContext3 = null) { if (request.IsRedirected) { if (LoadFromCache(context, request, request.RedirectUri, loggingContext1, loggingContext2, loggingContext3)) { return(true); } else { Caching.HTTPCacheService.DeleteEntity(request.RedirectUri); } } bool loaded = LoadFromCache(context, request, request.Uri, loggingContext1, loggingContext2, loggingContext3); if (!loaded) { Caching.HTTPCacheService.DeleteEntity(request.Uri); } return(loaded); }
private static Optional <CompositeGraphFingerprint> LogAndReturnFailure(LoggingContext loggingContext, BuildXLException ex) { Tracing.Logger.Log.FailedToComputeGraphFingerprint(loggingContext, ex.LogEventMessage); return(Optional <CompositeGraphFingerprint> .Empty); }
public static bool TryLoadAllFromCache(string context, HTTPRequest request, LoggingContext loggingContext1 = null, LoggingContext loggingContext2 = null, LoggingContext loggingContext3 = null) { // We will try to read the response from the cache, but if something happens we will fallback to the normal way. try { //Unless specifically constrained by a cache-control (section 14.9) directive, a caching system MAY always store a successful response (see section 13.8) as a cache entity, // MAY return it without validation if it is fresh, and MAY return it after successful validation. // MAY return it without validation if it is fresh! if (HTTPManager.Logger.Level == Logger.Loglevels.All) { HTTPManager.Logger.Verbose("ConnectionHelper", string.Format("[{0}] - TryLoadAllFromCache - whole response loading from cache", context), loggingContext1, loggingContext2, loggingContext3); } request.Response = HTTPCacheService.GetFullResponse(request); if (request.Response != null) { return(true); } } catch { HTTPManager.Logger.Verbose("ConnectionHelper", string.Format("[{0}] - TryLoadAllFromCache - failed to load content!", context), loggingContext1, loggingContext2, loggingContext3); HTTPCacheService.DeleteEntity(request.CurrentUri); } return(false); }
/// <summary> /// Tries to parse input line. /// </summary> /// <remarks> /// Input line must be of the form: /// full path /// or /// full path|comma separated <see cref="PathChanges"/> /// The former assumes that changes are <see cref="PathChanges.DataOrMetadataChanged"/>. /// </remarks> private static bool TryParseInput( LoggingContext loggingContext, string input, string filePath, int lineNo, out ChangedPathInfo changedPathInfo, string sourceRoot = null, DirectoryTranslator directoryTranslator = null) { Contract.Requires(loggingContext != null); Contract.Requires(!string.IsNullOrEmpty(input)); changedPathInfo = default; string[] splitInput = input.Split(s_inputSeparator); if (splitInput.Length > 2) { Logger.Log.InvalidFormatOfInputChange(loggingContext, input, filePath, lineNo); return(false); } string changedPath = splitInput[0].Trim(); string changesStr = null; if (splitInput.Length == 2) { changesStr = splitInput[1].Trim(); } // Assume data or metadata change if unspecified. PathChanges changes = PathChanges.DataOrMetadataChanged; try { if (!Path.IsPathRooted(changedPath)) { if (string.IsNullOrEmpty(sourceRoot)) { Logger.Log.InvalidChangedPathOfInputChange(loggingContext, changedPath, filePath, lineNo); return(false); } changedPath = Path.GetFullPath(Path.Combine(sourceRoot, changedPath)); } if (directoryTranslator != null) { changedPath = directoryTranslator.Translate(changedPath); } if (!string.IsNullOrEmpty(changesStr)) { if (!Enum.TryParse(changesStr, true, out changes)) { string validKinds = string.Join(", ", ((PathChanges[])Enum.GetValues(typeof(PathChanges))).Select(c => c.ToString())); Logger.Log.InvalidChangeKindsOfInputChange(loggingContext, changesStr, filePath, lineNo, validKinds); return(false); } } } catch (ArgumentException argumentException) { Logger.Log.InvalidInputChange(loggingContext, input, filePath, lineNo, argumentException.ToString()); return(false); } changedPathInfo = new ChangedPathInfo(changedPath, changes); return(true); }
/// <summary> /// Creates an instance of <see cref="GraphInputArtifactChanges"/>. /// </summary> public GraphInputArtifactChanges(LoggingContext loggingContext, IReadOnlyCollection <string> gvfsProjections) { Contract.Requires(loggingContext != null); m_loggingContext = loggingContext; m_gvfsProjections = gvfsProjections; }
/// <summary> /// Class constructor /// </summary> public GrpcWorkerServer(WorkerService workerService, LoggingContext loggingContext, string buildId) { m_workerService = workerService; m_loggingContext = loggingContext; m_buildId = buildId; }
public void writeMessage(Message message) { MessageDAL md = messagetoMessageDAL(message); using (var log = new LoggingContext()) { log.messages.Add(md); log.SaveChanges(); } }
/// <inheritdoc cref="ISdkResolverService.ResolveSdk"/> public override string ResolveSdk(int submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, string solutionPath, string projectPath) { SdkResult result = GetSdkResultAndCache(submissionId, sdk, loggingContext, sdkReferenceLocation, solutionPath, projectPath); return(result?.Path); }
public List<Message> readAllMessages(Message parameters, Boolean isOr) { List<Message> messagesToBack = new List<Message>(); using (var log = new LoggingContext()) { //IQueryable<MessageDAL> result; //if (!isOr) //{ // result = log.messages.Where(m => (m.message == parameters.messaggio) && (m.source == parameters.sorgente) && (m.categoryDAL.CategoryId == (int)parameters.tipo.idTipo)); //} //else //{ // result = log.messages.Where(m => (m.message == parameters.messaggio) || (m.source == parameters.sorgente) || (m.categoryDAL.CategoryId == (int)parameters.tipo.idTipo)); //} //if (result != null) //{ // messagesToBack = messagesDALtoMessages(result.ToList()); //} var query = from m in log.messages join cat in log.categories on m.TypeId equals cat.CategoryId select new Message { exception = m.exception, messaggio = m.message, id = m.MessageId, sorgente = m.source, timeStamp = m.timestamp, tipo = new Category{ idTipo = (CategoryType)cat.CategoryId, tipo = cat.name} }; messagesToBack = query.ToList(); } return messagesToBack; }
private void AssertEntryWrittenToDatabase(string level, string message) { using(var context = new LoggingContext(ConnectionStringName)) { Assert.That(context.Log.Any(e => e.Level == level && e.Message == message)); } }