Hopefully a quick question:
Previously with IdServ3, @leastprivilege had posted a handy blog entry to add a SeqEventService, which was registered via a Factory method as an EventService:
https://leastprivilege.com/2015/10/22/identityserver3-logging-monitoring-using-serilog-and-seq/
The Factory approach, and indeed the Event Service seems to be no longer with us in IdServ4.
Is such Event logging available by some other approach with IdServ4?
We will still have the event service. If you write a custom one, then put it into DI.
@brockallen
Thanks Brock,
Just to be clear, the EventService will be added later, or is already in place...? I have looked through the source and was unable to find this, or an extension point where one could be added...
Probably a case of me just needing to be patient while the core stuff is finalised...?
Ok, forget that... all is working. As my mum would say, I was 'looking with my elbows'.
If anybody else wants to log internal Events in this way:
A) Take the SeqEventService class mentioned in the blog post at:
https://leastprivilege.com/2015/10/22/identityserver3-logging-monitoring-using-serilog-and-seq/
Included here for simplicities sake:
class SeqEventService : IEventService
{
static readonly ILogger Log;
static SeqEventService()
{
Log = new LoggerConfiguration()
.WriteTo.Seq("http://localhost:5341")
.CreateLogger();
}
public Task RaiseAsync<T>(Event<T> evt)
{
Log.Information("{Id}: {Name} / {Category} ({EventType}), Context: {@context}, Details: {@details}",
evt.Id,
evt.Name,
evt.Category,
evt.EventType,
evt.Context,
evt.Details);
return Task.FromResult(0);
}
}
B) Instead of registering it with the Factory as described, use the following in your ConfigureServices method:
services.AddSingleton(typeof(IEventService), typeof(SeqEventService));
C) Ensure that the relevant EventOptions are set, for example, in your ConfigureServices :
var identityBuilder = services.AddIdentityServer(options =>
options.EventsOptions = new EventsOptions
{
RaiseErrorEvents = true,
RaiseFailureEvents = true,
RaiseInformationEvents = true,
RaiseSuccessEvents = true
});
It's very important to do this, as the default for each is false, which is of course logical.
For anyone else that comes across this, the DefaultEventService will write the event out to the logger registered with the DI system (Serilog/Seq if you have it configured so).
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Ok, forget that... all is working. As my mum would say, I was 'looking with my elbows'.
If anybody else wants to log internal Events in this way:
A) Take the
SeqEventServiceclass mentioned in the blog post at:https://leastprivilege.com/2015/10/22/identityserver3-logging-monitoring-using-serilog-and-seq/
Included here for simplicities sake:
B) Instead of registering it with the Factory as described, use the following in your
ConfigureServicesmethod:C) Ensure that the relevant EventOptions are set, for example, in your
ConfigureServices:It's very important to do this, as the default for each is false, which is of course logical.