Skip to content

Commit 0de0083

Browse files
Disable session tracking by default
1 parent 338a827 commit 0de0083

File tree

5 files changed

+38
-23
lines changed

5 files changed

+38
-23
lines changed

doc/reference/modules/configuration.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,17 +1031,18 @@ var session = sessions.OpenSession(conn);
10311031
<literal>track_session_id</literal>
10321032
</entry>
10331033
<entry>
1034-
Set whether the session id should be tracked in logs or not. When <literal>true</literal>, each
1034+
Set whether the session id should be track-able in logs or not. When <literal>true</literal>, each
10351035
session will have an unique <literal>Guid</literal> that can be retrieved with
10361036
<literal>ISessionImplementor.SessionId</literal>, otherwise <literal>ISessionImplementor.SessionId</literal>
10371037
will be <literal>Guid.Empty</literal>.
10381038
<para>
10391039
Session id is used for logging purpose and can also be retrieved on the static property
10401040
<literal>NHibernate.Impl.SessionIdLoggingContext.SessionId</literal>, when tracking is enabled.
1041+
Some third party tools depend on it, like NHibernate Profiler.
10411042
</para>
10421043
<para>
10431044
Disabling tracking by setting <literal>track_session_id</literal> to <literal>false</literal>
1044-
increases performances. Default is <literal>true</literal>.
1045+
increases performances. Default is <literal>false</literal>.
10451046
</para>
10461047
<para>
10471048
<emphasis role="strong">eg.</emphasis>

src/NHibernate.Test/NHSpecificTest/GH1391/Fixture.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,24 +131,36 @@ public async Task DisabledAsync()
131131
[Test]
132132
public void XmlConfiguration()
133133
{
134-
const string xml = @"<?xml version='1.0' encoding='utf-8' ?>
134+
const string falseConfig = @"<?xml version='1.0' encoding='utf-8' ?>
135135
<hibernate-configuration xmlns='urn:nhibernate-configuration-2.2'>
136136
<session-factory name='NHibernate.Test'>
137137
<property name='track_session_id'>
138138
false
139139
</property>
140140
</session-factory>
141141
</hibernate-configuration>";
142-
143-
var cfgXml = new XmlDocument();
144-
cfgXml.LoadXml(xml);
142+
const string trueConfig = @"<?xml version='1.0' encoding='utf-8' ?>
143+
<hibernate-configuration xmlns='urn:nhibernate-configuration-2.2'>
144+
<session-factory name='NHibernate.Test'>
145+
<property name='track_session_id'>
146+
true
147+
</property>
148+
</session-factory>
149+
</hibernate-configuration>";
145150

146151
var cfg = new Configuration();
147-
using (var xtr = new XmlTextReader(xml, XmlNodeType.Document, null))
152+
using (var xtr = new XmlTextReader(falseConfig, XmlNodeType.Document, null))
148153
{
149154
cfg.Configure(xtr);
150155
Assert.That(PropertiesHelper.GetBoolean(Environment.TrackSessionId, cfg.Properties, true), Is.False);
151156
}
157+
158+
cfg = new Configuration();
159+
using (var xtr = new XmlTextReader(trueConfig, XmlNodeType.Document, null))
160+
{
161+
cfg.Configure(xtr);
162+
Assert.That(PropertiesHelper.GetBoolean(Environment.TrackSessionId, cfg.Properties, false), Is.True);
163+
}
152164
}
153165
}
154166
}

src/NHibernate/Cfg/Environment.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,14 @@ public static string Version
259259
public const string OracleUseNPrefixedTypesForUnicode = "oracle.use_n_prefixed_types_for_unicode";
260260

261261
/// <summary>
262-
/// <para>Set whether tracking the session id or not. When <see langword="true"/>, each session
263-
/// will have an unique <see cref="Guid"/> that can be retrieved by <see cref="ISessionImplementor.SessionId"/>,
264-
/// otherwise <see cref="ISessionImplementor.SessionId"/> will always be <see cref="Guid.Empty"/>. Session id
265-
/// is used for logging purpose that can be also retrieved in a static context by
266-
/// <see cref="NHibernate.Impl.SessionIdLoggingContext.SessionId"/>, where the current session id is stored,
267-
/// when tracking is enabled.</para>
268-
/// In case the current session id won't be used, it is recommended to disable it, in order to increase performance.
269-
/// <para>Default is <see langword="true"/>.</para>
262+
/// <para>Set whether the session id should be track-able in logs or not. When <see langword="true"/>, each session
263+
/// will have an unique <see cref="Guid"/> that can be retrieved with <see cref="ISessionImplementor.SessionId"/>,
264+
/// otherwise <see cref="ISessionImplementor.SessionId"/> will be <see cref="Guid.Empty"/>.</para>
265+
/// <para>Session id is used for logging purpose and can also be retrieved on the static property
266+
/// <see cref="NHibernate.Impl.SessionIdLoggingContext.SessionId"/>, when tracking is enabled.
267+
/// Some third party tools depend on it, like NHibernate Profiler.</para>
268+
/// <para>Disabling tracking by setting <c>track_session_id</c> to <see langword="false"/> increases performances.</para>
269+
/// <para>Default is <see langword="false"/>.</para>
270270
/// </summary>
271271
public const string TrackSessionId = "track_session_id";
272272

src/NHibernate/Cfg/SettingsFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public Settings BuildSettings(IDictionary<string, string> properties)
304304
// NHibernate-specific:
305305
settings.IsolationLevel = isolation;
306306

307-
bool trackSessionId = PropertiesHelper.GetBoolean(Environment.TrackSessionId, properties, true);
307+
bool trackSessionId = PropertiesHelper.GetBoolean(Environment.TrackSessionId, properties, false);
308308
log.Debug("Track session id: " + EnabledDisabled(trackSessionId));
309309
settings.TrackSessionId = trackSessionId;
310310

src/NHibernate/nhibernate-configuration.xsd

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,15 @@
196196
<xs:enumeration value="track_session_id">
197197
<xs:annotation>
198198
<xs:documentation>
199-
Set whether tracking the session id or not. When true, each session will have an unique Guid
200-
that can be retrieved by ISessionImplementor.SessionId, otherwise ISessionImplementor.SessionId will
201-
always be Guid.Empty. Session id is used for logging purpose that can be also retrieved in a static
202-
context by SessionIdLoggingContext.SessionId, where the current session id is stored, when tracking
203-
is enabled. In case the current session id won't be used, it is recommended to disable it, in order
204-
to increase performance.
205-
True by default.
199+
Set whether the session id should be track-able in logs or not. When true, each
200+
session will have an unique Guid that can be retrieved with
201+
ISessionImplementor.SessionId, otherwise ISessionImplementor.SessionId
202+
will be Guid.Empty.
203+
Session id is used for logging purpose and can also be retrieved on the static property
204+
NHibernate.Impl.SessionIdLoggingContext.SessionId, when tracking is enabled.
205+
Some third party tools depend on it, like NHibernate Profiler.
206+
Disabling tracking by setting track_session_id to false increases performances.
207+
Default is false.
206208
</xs:documentation>
207209
</xs:annotation>
208210
</xs:enumeration>

0 commit comments

Comments
 (0)