Comments (10)
I wouldn't copy the custom HTTP client from my test assembly, it contain a lot of stuff that are only relevant for tests. You should go with something that looks like this:
public class SerilogHttpClient : IHttpClient
{
private readonly HttpClient httpClient;
public SerilogHttpClient()
{
var handler = new HttpClientHandler { UseDefaultCredentials = true };
httpClient = new HttpClient(handler);
}
public Task<HttpResponseMessage> PostAsync(string requestUri, HttpContent content) => httpClient.PostAsync(requestUri, content);
public void Dispose() => httpClient?.Dispose();
}
from serilog-sinks-http.
Hi daver77!
Are you experiencing the exception in tests or in your running application? Can you point me to your code or perhaps provide a sample application that experience the problem?
from serilog-sinks-http.
Hi, I get the error when the Log is initialising
Log.Logger = new LoggerConfiguration()
.ReadFrom.AppSettings()
.CreateLogger();
<appSettings>
<add key="serilog:minimum-level" value="Verbose" />
<add key="serilog:using:Http" value="Serilog.Sinks.Http" />
<add key="serilog:write-to:Http"/>
<add key="serilog:write-to:Http.requestUri" value="http://myurl/api/serilog/5" />
<add key="serilog:write-to:Http.httpClient" value="SerilogTest.SerilogHttpClient, SerilogTest" />
</appSettings>
namespace SerilogTest
{
/// <summary>
/// An implementation of IHttpClient to log errors via the Serilog HTTP sink
/// </summary>
public class SerilogHttpClient : IHttpClient
{
private int numberOfPosts;
public SerilogHttpClient()
{
Instance = this;
}
public static SerilogHttpClient Instance { get; set; }
public HttpClient Client { get; set; }
public int NumberOfPosts => numberOfPosts;
public async Task<HttpResponseMessage> PostAsync(string requestUri, HttpContent content)
{
using (var handler = new HttpClientHandler { UseDefaultCredentials = true })
using (Client = new HttpClient(handler))
{
Interlocked.Increment(ref numberOfPosts);
return await Client.PostAsync(requestUri, content);
}
}
public void Dispose()
{
Client?.Dispose();
Client = null;
}
}
}
from serilog-sinks-http.
I'll build a sample application looking like yours to see if I experience the same problem.
from serilog-sinks-http.
Sample project attached if it helps
from serilog-sinks-http.
Nice, I'll take a look at it!
from serilog-sinks-http.
I've just finished putting together a very basic example showing this sink writing log events to a log server over HTTP, you can find it here: https://github.com/FantasticFiasco/serilog-sinks-http-sample-dotnet-framework
While I take a look at your code, can you try to run my sample and see if you experience any problems?
from serilog-sinks-http.
I have verified that I get the same exception using your sample, but don't yet know why.
from serilog-sinks-http.
Something is wrong with your project. I cannot run your attached sample unless I remove all NuGet packages and then add them again. It is not specific to .NET 4.6.2 because it doesn't work in .NET 4.6.1 either.
I tried creating a new project from scratch:
- Start Visual Studio
- Create new project of type ASP.NET Web Application (.NET Framework) and make sure .NET Framework 4.6.2 is selected
- Chose Web Forms as template
- When solution is loaded, add NuGet package Serilog.Sinks.Http
- Add the following class to the project:
public class SerilogHttpClient : IHttpClient
{
private readonly HttpClient httpClient;
public SerilogHttpClient()
{
httpClient = new HttpClient();
}
public Task<HttpResponseMessage> PostAsync(string requestUri, HttpContent content)
{
return httpClient.PostAsync(requestUri, content);
}
public void Dispose() => httpClient?.Dispose();
}
- In
Global.asax
inApplication_Start
method append the following lines of code:
Log.Logger = new LoggerConfiguration()
.WriteTo.Http("http://myurl/api/serilog/5", httpClient: new SerilogHttpClient())
.CreateLogger();
Log.Error("Error");
- Start the application and verify that no exception is thrown
from serilog-sinks-http.
I am closing this issue due to inactivity. I assume your problem was solved since no other issues where raised.
from serilog-sinks-http.
Related Issues (20)
- Add README.md to NuGet package
- Remove _typeTag from the RenderedMessage HOT 4
- Project Requires Specific Version of Microsoft.Extensions.Configuration.Abstractions HOT 3
- Change non-durable sink to require an explicit queue limit, or null for no limit HOT 2
- DurableHttpSink sometimes split log event and sometime merge other log event in-between HOT 9
- License years in Directory.Build.props is not updated
- Remove support for .NET 4.5 HOT 1
- custom http client version 8.0 HOT 3
- configure via appsettings: logEventsInBatchLimit failing HOT 4
- Bookmark file is being used by another process HOT 27
- Test
- UnauthorizedAccessException D:\Windows\system32\Buffer.bookmark on Azure App Service (IIS) HOT 3
- Escape characters inside my Post Body HOT 3
- Add ability to select the extension of log files on durability HOT 7
- Add SSL Support HOT 3
- Bufferfile is not processed after deployment. HOT 5
- Ingest fetch call from blazor does not pass CORS check HOT 13
- Allow Option For Archiving Rolled Buffer Files HOT 2
- Log level switch
- Add new parameter to limit size of the internal queue by log events count HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serilog-sinks-http.